* this overscan-rout gives us ruoghly 370x260 pixels in 4 bitplanes
* (actally about 376x258 visible on screen (mine),
*  out of about 460x280 that the rout generates
* The start of the screen is videoadress+222

	text

L0:
	pea	$400.w
	move	#$20,-(a7)		;Super
	trap	#1
	move.l	d0,L120+2

	move.b	#18,$FFFFFC02.w		;turn mouse off
	movem.l	$FFFF8240.w,d0-d7	;save cols

	lea	save_cols(pc),a0
	movem.l	d0-d7,(a0)

	move.l	$44E.w,d5
	lea	$68000.l,a0		;set videoadress
	lea	196(a0),a6
	move.l	a6,$44E.w		
	lea	$FFFF8201.w,a6
	move.l	a0,d0
	lsr.l	#8,d0
	movep.w	d0,0(a6)
	lea	$68000,a0
	move	$12000,d1
.loop					;clear screen
	move.l	#0,(a0)+
	dbra	d1,.loop

	move.l	$44E.w,a0		;get adress for logo
	add.l	#26+230*220,a0		;actual screenstart is at
 					;video-adress+222
	lea	logo,a1
	moveq	#64,d1			;put 64 lines
put_line:
	move.l	a0,a2
	moveq	#15,d0
put_loop:
	move.l	(a1)+,(a2)+
	dbra	d0,put_loop

	lea	230(a0),a0		;next line
	dbra	d1,put_line		;each line consists of
					;230 bytes wich is 460 pixel
	lea	$FFFF8242.w,a6
	move.w	#$070,(a6)+
	move.w	#$7070,(a6)+
	move.w	#$700,(a6)+
	move.w	#$7700,(a6)+
	move.w	#$070,(a6)+
	move.w	#$7007,(a6)+
	move.w	#$070,(a6)+
	move.w	#$070,(a6)+
	move.w	#$070,(a6)+
	move.w	#$070,(a6)+
	move.w	#$070,(a6)+
	move.w	#$070,(a6)+

	lea	$FFFFFA15.w,a6
	move.b	(a6),d7			;save IMRB
	clr.b	(a6)

	lea	$FFFF8209.w,a0		*Video counter
	lea	87(a0),a1		*Rez
	lea	1(a0),a2		*Hz

	clr.b	d0
	lea	$FFFF8240.w,a4

	moveq	#2,d1			;install VBI
	lea	$70.w,a5
	move.l	(a5),d6
	lea	vbi(pc),a3
	move.l	a3,(a5)

	clr	$800.w
demoloop:
	stop	#$2300
	cmpi.b	#$B9,$FFFFFC02.w	;wait keypress
	bne.s	demoloop

	move.l	d6,(a5)			;restore VBI
	move.b	d7,(a6)			;restore IMRB

	move.l	d5,$44E.w		;restore videoadress
	lea	$FFFF8201.w,a0
	lsr.l	#8,d5
	movep.w	d5,0(a0)

	movem.l	save_cols(pc),d0-d7	;restore colours
	movem.l	d0-d7,$FFFF8240.w
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	$fffffc02.w,d0
	move.b	#8,$FFFFFC02.w

L120:	pea	$55555555.l		;Xit super
	move	#$20,-(a7)
	trap	#1

	clr	-(a7)			Exit program
	trap	#1

save_cols:
	dc.w	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
****************************************************************
*        The syncrout for the overscan starts here
*        Alla the comments made by Greenface of 2-Life Crew
*	 This is a special rewritten syncrout

vbi:
	move	#1435,d2		;\
wait_17k_cycles:			;Wait 17244 clockcycles
	dbra	d2,wait_17k_cycles	;/

	move.b	#16,d2
	move.b	d0,(a2)		;freq= 60Hz

	moveq	#1,d3		;\
.loop_60_1:			;Wait 36 clockcycles
	dbra	d3,.loop_60_1	;/

	move.b	d1,(a2)		;freq= 50Hz

	move	#3,d3		;\
.loop_exp			;wait 68 clockcycles
	dbra	d3,.loop_exp	;|
	nop			;|
	nop			;/

wait_video_run:			;This part syncs in
	move.b	(a0),d3		;with the hbl
	beq.b	wait_video_run	;
	sub.b	d3,d2		;(the part before opens
	lsl.b	d2,d3		;the upper border)

	lea	colors(pc),a0	;a0=adress to colour-table
	move	#228-1,d2		;how many times through hbl? 228

	move	#16,d3		;\
.loop_sub1_1:			;wait 216 clockcycles
	dbra	d3,.loop_sub1_1	;/

hblsync_rout1:
	nop			;\
	nop			;|
	nop			;|
	move	#$3,d3		;waits 20 clockcycles

	move.b	d0,(a2)		;freq= 60Hz
	move.b	d1,(a2)		;freq= 50Hz

.loop_sub1_d:			;waits 52 clockcycles
	dbra	d3,.loop_sub1_d	;/

	move.b	d1,(a1)		;freq= 71.25Hz		cracks right
	nop			;wait 4 clockcycles	border
	move.b	d0,(a1)		;freq= 50Hz

	move	#$2,d3		;\
.loop_sub1_e:			;wait 48 clockcycles
	dbra	d3,.loop_sub1_e	;/

	move.b	d1,(a1)		;freq= 71.25Hz		cracks left
	nop			;wait 4 clockcycles	border
	move.b	d0,(a1)		;freq= 50Hz

	move	#25,d3		;\
.loop_sub1_f:			;waits 324 clockcycles
	dbra	d3,.loop_sub1_f	;/

	dbra	d2,hblsync_rout1	;and another time! 227 times more
***************************

	nop
	nop
	nop
	nop
	
	move.b	d0,(a2)		;freq= 60Hz
	move.b	d1,(a2)		;freq= 50Hz
	move	#43,d2		;how many times through sub1? 44...

	moveq	#2,d3		;\
.loop_50_1:			;wait 48 clockcycles
	dbra	d3,.loop_50_1	;/

	move.b	d1,(a1)		;freq= 71.25Hz
	nop			;wait 4 clockcycles
	move.b	d0,(a1)		;freq= 50Hz
	move.b	d0,(a2)		;freq= 60Hz

	move	#$1,d3		;\
.loop_60_2:			;wait 40 clockcycles
	dbra	d3,.loop_60_2	;|
	nop			;/

	move.b	d1,(a1)		;freq= 71.25Hz
	nop			;wait 4 clockcycles
	move.b	d0,(a1)		;freq= 60Hz
	move	(a0)+,(a4)	;sets colour 0
	move.b	d1,(a2)		;freq= 50Hz

	moveq	#24,d3		;\
.loop_sub1_2:			;wait 320 clockcycles
	dbra	d3,.loop_sub1_2	;|
	nop			;/
	nop

****************************************
hblsync_rout:
	nop			;\
	nop			;|
	move	#$3,d3		;waits 20 clockcycles
	nop			;/

	move.b	d0,(a2)		;freq= 60Hz
	move.b	d1,(a2)		;freq= 50Hz

.loop_sub1_a:			;waits 52 clockcycles
	dbra	d3,.loop_sub1_a	;/

	move.b	d1,(a1)		;freq= 71.25Hz		cracks right
	nop			;wait 4 clockcycles	border
	move.b	d0,(a1)		;freq= 50Hz

	move	#$2,d3		;\
.loop_sub1_b:			;wait 48 clockcycles
	dbra	d3,.loop_sub1_b	;/

	move.b	d1,(a1)		;freq= 71.25Hz		cracks left
	nop			;wait 4 clockcycles	border
	move.b	d0,(a1)		;freq= 50Hz
	move	(a0)+,(a4)	;sets colour 0

	move	#$18,d3		;\
.loop_sub1_c:			;waits 312 clockcycles
	dbra	d3,.loop_sub1_c	;/

	dbra	d2,hblsync_rout	;and another time! (227 or 43 times more)

****************************************
	nop
	nop
	nop
	nop

	move.b	d0,(a2)		;freq= 60Hz
	move.b	d1,(a2)		;freq= 50Hz

	move	#$2,d3		;\
.loop_50_2:			;wait 52 clockcycles
	dbra	d3,.loop_50_2	;|
	nop			;/

	move.b	d1,(a1)		;freq= 71.25Hz
	nop			;wait 4 clockcycles
	move.b	d0,(a1)		;freq= 50Hz
	clr	(a4)		;sets colour 0 to black
	lea	-87(a1),a0	;restores a0 to $ff8209
	rte

**************************************************
	data
colors:
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
	dc.w	$017,$027,$037,$047,$057,$067,$077
	dc.w	$177,$277,$377,$477,$577,$677,$777
save_regs: 
	ds.l	15
logo:
	incbin	D:\fontsetc\goesover.img
	end
