;File name:	BORDER_2.S			Revised:	1993.07.01
;Created by:	Gunter (6719)			Created:	xxxx.xx.xx
;Revised by:	Ulf Ronald Andersson (URAn)
;Remarks:	Color only!
;-----------------------------------------------------------------------------
;
	output	.TOS
;
	include	URAn_DOS.S
	include	URAn_LA.S
;
;	text
;
;-----------------------------------------------------------------------------
;
start:
	gemdos	Super,!
	move.l	d0,savereg
	move.l	#loc_st_end,sp
;
	move.l	(_sysbase).w,a0
	move.l	os_selfbeg_p(a0),a0
	move.l	os_kbshift_p(a0),kbshift_p
;
	xbios	Ikbdws,!,moff
	_a_hide_c			;mouse off
;;;	move.b	#$12,(hw_kbdata).w	;mouse off
;	
	move.b	(conterm).w,old_conterm		;save key stats
	bclr 	#0,(conterm)			;no keyclick
	bclr 	#1,(conterm)			;no repeat key
;
	xbios	Getrez
	move.w	d0,oldrez
	move.l	(_v_bas_ad).w,oldscr
	move.l	#screen_bf+$100,screen_p	;new screen address
	clr.b	screen_p+3
;
	movem.l	(hw_pal).w,d0-d7
	movem.l	d0-d7,oldpal
	move.b	#$02,(hw_syn).w
;
	bsr	prepare
	bsr	hblon
;
	move.l	kbshift_p(pc),a0
.loop_1:
	tst.b	(a0)
	beq.s	.loop_1
.exit_1:
;
	bsr	hbloff
;
	movem.l	oldpal,d0-d7
	movem.l	d0-d7,(hw_pal).w
	xbios	Setscreen|_ind,oldscr,oldscr,oldrez
;
	move.b	old_conterm,(conterm).w		;restore key stats
;;;	move.b	#8,(hw_kbdata).w	;mouse on
	xbios	Ikbdws,!,mon
	_a_show_c		;mouse on
	gemdos	Super|_ind,savereg
	gemdos	Pterm0
;
;-----------------------------------------------------------------------------
;
kbshift_p	dc.l	0
oldrez:		dc.w	0
oldscr:		dc.l	0
savereg:	dc.l	0
screen_p:	dc.l	0
oldpal:		dcb.w	16,0
mon:		dc.b	$08
moff:		dc.b	$12
old_conterm:	dc.b	0
		even
;
;-----------------------------------------------------------------------------
;
hblon:
	move.l	(iv_time_b).w,oldtb	;preserve vectors
	move.l	(ev_vbi).w,old_vbi
	move.l	(ev_vbi).w,new_vbib+2
	move.b	$fffffa07.w,old07
	move.b	$fffffa09.w,old09
	move.b	$fffffa0f.w,old0f
	move.b	$fffffa11.w,old11
	move.b	(hw_tbcr).w,old1b
	and.b	#$df,$fffa09	;disable Timer C
	and.b	#$fe,$fffa07	;disable Timer B
	move.l	#newtb,(iv_time_b).w
	move.l	#new_vbi,(ev_vbi).w
	or.b	#1,$fffffa07.w	;Timer B enable
	or.b	#1,$fffffa13.w
	rts
;
;
hbloff:
	move.w	sr,-(sp)
	move.w	#$2700,sr
	move.b	old07(pc),$fffffa07.w	;restore all registers
	move.b	old09(pc),$fffffa09.w
	move.b	old0f(pc),$fffffa0f.w
	move.b	old11(pc),$fffffa11.w
	move.b	old1b(pc),(hw_tbcr).w
	move.l	oldtb,(iv_time_b).w		;restore vectors
	move.l	old_vbi,(ev_vbi).w
	move.w	(sp)+,sr
	rts
;
;-----------------------------------------------------------------------------
;
old_vbi:	dc.l	0
oldtb:	dc.l	0
old07:	dc.b	0
old09:	dc.b	0
old0f:	dc.b	0
old11:	dc.b	0
old1b:	dc.b	0
	even
;
;-----------------------------------------------------------------------------
;
new_vbi:
	clr.b	(hw_tbcr).w
	move.b	#199,(hw_tbdr).w
	move.b	#8,(hw_tbcr).w
new_vbib:
	jmp	$000000.l
;
;-----------------------------------------------------------------------------
;
newtb:
	clr.b	(hw_tbcr).w	;timer stop
	movem.l	d0-d1/a0-a1,-(sp)
	move.w	#$fa21,a1
	move.b	#47,(a1)
	move.b	#8,(hw_tbcr).w
;
	move.b	(a1),d0
wait:				;wait for the end of the last line
	cmp.b	(a1),d0
	beq	wait
	clr.b	(hw_syn).w	;60 Hz
;
	moveq	#3,d0
nopi2:				;wait a while
	nop
	dbf	d0,nopi2
;now we are in the left border
	move.b	#2,(hw_syn).w	;50 Hz
	move.w	#$777,(hw_pal)	;Mark
;
	movem.l	(sp)+,d0-d1/a0-a1
	move.l	#newtb2,(iv_time_b).w
	bclr	#0,$fffffa0f.w	;end of interrupt
	rte
;
;
newtb2:
	clr.b	(hw_tbcr).w	;timer stop
	movem.l	d0-d1/a0-a1,-(sp)
	move.w	#$fa21,a1
	move.b	#200,(a1)	;dummy value
	move.b	#8,(hw_tbcr).w
	move.l	#newtb,(iv_time_b).w
	move.l	old_vbi(pc),(ev_vbi).w	;level 4 not needed anymore
;
	move.b	(a1),d0
wait2:				;wait for end of line
	cmp.b	(a1),d0
	beq	wait2
;
	moveq	#35,d0
scandelay:			;loop for 18 H-lines
	rept	125
	nop
	endr
	dbf	d0,scandelay
;
	moveq	#29,d0
wait3:				;loop appx half a H-line
	nop
	dbf	d0,wait3
;upper border, 1st try
	clr.b	(hw_syn).w	;60 Hz
	moveq	#3,d0
nopi3:				;wait a while
	nop
	dbf	d0,nopi3
;now we are in the left border
	move.b	#2,(hw_syn).w	;50 Hz
	move.w	#$700,(hw_pal)	;Mark
	moveq	#14,d0
scandelay2:			;loop 7.5 H-lines
	rept	125
	nop
	endr
	dbf	d0,scandelay2
;
	moveq	#23,d0
wait4:
	nop
	dbf	d0,wait4
;Upper border, 2nd try
	clr.b	(hw_syn).w	;60 Hz
	moveq	#3,d0
nopi4:				;wait a while
	nop
	dbf	d0,nopi4
;Left border reached
	move.b	#2,(hw_syn).w	;50 Hz
	move.w	#$070,(hw_pal)	;Mark
;
	clr.b	(hw_tbcr).w	;timer stop
	move.b	#199+13,(hw_tbdr).w
	move.b	#8,(hw_tbcr).w
;
	movem.l	(sp)+,d0-d1/a0-a1
	bclr	#0,$fffffa0f.w	;end of interrupt
	rte
;
;-----------------------------------------------------------------------------
;
prepare:
	xbios	Setscreen|_ind,screen_p,screen_p,#0

	movem.l	graphic(pc),d6-d7
	move.l	screen_p(pc),a0
	move	#300-1,d1	;fill 300 lines

alles:
	moveq	#20-1,d0	;20*16 pixels = one scanline
zeile1:
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	dbf	d0,zeile1
	dbf	d1,alles

	movem.l	pal1(pc),d0-d3
	movem.l	d0-d3,(hw_pal).w
	rts
;
;-----------------------------------------------------------------------------
;
graphic:
	dc.w	$55AA,$33CC,$0FF0,$0000
;
pal1:
	dc.w	$000,$111,$222,$333,$444,$555,$666,$777
;
;-----------------------------------------------------------------------------
;
	section	bss
;
loc_stack:	ds.l	$1000
loc_st_end:	ds.l	4
screen_bf:	ds.b	$20000
;
;-----------------------------------------------------------------------------
;End of file:	BORDER_2.S
