*********************************************************
*							*
*		Changing the Frequency,			*
*							*
*			verbrochen von Level Four ASD	*
*							*
*	Compare the new and the old frequency by	*
*	 	 pushing the right mouse-button	!	*
*							*
* PS: change the value 'line'				*
*							*
* PPS: ya have an old tv-set displaying this ???	*
*   FORGET IT !!! BUY A MONITOR (Hi Snoopy,don't worry) *
*							*
*	ya have a multisync-monitor ???			*
*	 YEAH !!! decrease 'line' and be happy !!!	*
*********************************************************

line = 240			;line MUST be LOWER than 312 !!!!!!!!
				;240 should run on every 'normal' monitor
				;like 1081,1084 or PHIL. 8833 etc.
				;line 240 is equal to 64.8 Hz
				;(32.4 Hz in this case, coz of interlace)
;Test your monitor with this formula:
;Your personal Hz = 311/line * 50 Hz
;(take lowest 'line'-value without a 'mad' screen)

	jmp	start

	org	$40000
	load	$40000

start:
	move.l	$80.w,oldtrap
	move.l	#start2,$80.w
	trap	#0
	move.l	oldtrap(pc),$80.w
	rts

oldtrap: dc.l 0
start2:
	move.w	#$2700,sr		;sorry, but i hate to be
					;interrupted while working
	move.l	4.w,a6
	lea	grafname(pc),a1
	jsr	-408(a6)
	move.l	d0,a1
	move.l	38(a1),oldcopper
	move.l	50(a1),aktcopper
	jsr	-414(a6)

	move.w	$dff002,olddma
	or.w	#$8000,olddma
	move.w	$dff01c,oldint
	or.w	#$8000,oldint

	move.w	#$7fff,$dff09a
	move.w	#$7fff,$dff096

	bsr.l	prog_begin

	move.l	oldcopper(pc),$dff080

	move.w	#$7fff,$dff09a
	move.w	#$7fff,$dff096

	move.l	oldcopper(pc),$dff080
	move.l	oldcopper(pc),$dff084
	clr.w	$dff088

	move.w	olddma(pc),$dff096
	move.w	oldint(pc),$dff09a

	rte

prog_begin:
	bsr.l	get_pointers	;search for pointers to seka-screen

	move.w	#$0000,$dff02a		;used to syncronize interlace
	move.l	#clist,$dff080
	clr.w	$dff088			;set the new copperlist
sync:
	cmp.b	#255,$dff006		;this is also for interlace
	bne.s	sync			;syncronisation

	move.w	#$8380,$dff096		;copper and screen-dma
mouse:
	cmpi.b	#100,$dff006
	bne.s	mouse
mouse2:
	move.l	$dff004,d0		;read the video-beam-position
	and.l	#$0001ff00,d0
	cmp.l	#line*256,d0		;did he reached our magic line ?
	bne.s	mouse2			;wait a little if he did not

	move.l	$dff004,d1		;read it again
	and.l	#$80000000,d1		;save the interlace-bit
	or.l	#$00013778,d1		;that's where the video-beam
					;goes (where he is forced to go)
					;now we have to syncronize the
					;video-beam using its HPOS.
	move.b	$dff007,d0		;read the horizontal position.
	sub.b	#20,d0		;sub because the VBEAM is too fast for us
	neg.b	d0			;after this two commands the
	lsl.b	d0,d0			;video-beam is absolutely on the
					;same position.
				;lsl.b d0,d0 is only used for equalize
				;the HPOS by wasting processor time which
				;is in this case dependened of the HPOS:
				;move.b $dff007,d0 ... lsl.b d0,d0

	btst	#10,$dff016
	beq.s	flicker		;new-hertz mode only if the right mb
				;is not pressed
	move.l	d1,$dff02a	;here the VBEAM gets the kick (auah!)
flicker:
	move.l	plane2(pc),d0		;everything that follows is
	move.w	d0,screen_pt+6		;of lowest interest
	move.w	d0,screen_pt2+6
	swap	d0
	move.w	d0,screen_pt+2
	move.w	d0,screen_pt2+2

	move.l	plane(pc),d0
	move.l	plane2(pc),plane
	move.l	d0,plane2

	btst	#6,$bfe001
	bne.L	mouse

	rts

get_pointers:		;find position of the seka-screen
	move.l	aktcopper(pc),a0
	move.w	#$00e0,d0
	bsr.l	find_cop
	move.w	2(a0),d0
	swap	d0
	move.w	6(a0),d0
	move.l	d0,plane
	add.l	#80,d0
	move.l	d0,plane2
	rts
find_cop:
	cmp.w	(a0),d0
	beq.s	find_cop_end
	addq.w	#4,a0
	bra.s	find_cop
find_cop_end:
	rts

plane: dc.l 0
plane2: dc.l 0

grafname: dc.b "graphics.library",0
	even
oldcopper: dc.l 0
aktcopper: dc.l 0

olddma:	dc.w 0
oldint: dc.w 0

clist:
	dc.l $01000000
	dc.l $008e1c81,$009049c1
	dc.l $0092003c,$009400d4
	dc.l $01080050,$010a0050
	dc.l $01040000
	dc.l $01020000
	dc.l $01440000,$01460000

	dc.l $01800777,$0182000c
	dc.l $0807fffe
	dc.l $01009204
screen_pt:
	dc.l $00e00000,$00e20000

	dc.l $9c07fffe
screen_pt2:
	dc.l $00e00000,$00e20000

	dc.l $fffffffe

End:
