*----------------------------------------------------------------------------*
		TEXT
*----------------------------------------------------------------------------*

		*-------------*
		cnop	0,16
INIT_VIDEO
	* type de moniteur connect‚, en vrai!
		bfextu	($ffff8006.w,za0){0:2},d0
		move	d0,monitor

	* mode pal ou ntsc pour les modes
		move	nvm_video(a6),d0
		and	#_pal,d0
		move	d0,pal

	* cherche le mode video
		clr	d0		;sm124
		tst	monitor(pc)
		beq.s	.ok
		btst	#0,monitor+1(pc)
		bne.s	.tv
		moveq	#3,d0		;vga
		bra.s	.ok
.tv
		moveq	#1,d0		;tv ntsc
		tst	pal(pc)
		beq.s	.ok
		moveq	#2,d0		;tv pal
.ok
		move.l	(video_list.w,pc,d0*4),cfg_param
	* change de r‚sol
		bsr	set_video

		*-------------*

		rts

		*-------------*

*-------------------------------------------------------------------------*

		*-------------------*
		* Valide un mode vid‚o … passer
		* Utilis‚ par le menu.
		* D0: mode … valider
		* =>D0: mode valid‚
		*-------------------*
		cnop	0,16
V_modevalid
		move.l	d1,-(sp)
		move.l	d2,-(sp)

		move	monitor(pc),d1
		tst	d1
		bne.s	.pas_sm124
			 ;FSOPV8NNN
		move	#%000001000,d0
		bra	.mode_ok
.pas_sm124
		btst	#0,d1
		bne.s	.tv
.vga
		and	#%110111111,d0	;garde le bit pal
		move	d0,d1		;car ca pourrait
		and	#%111,d1		;servir pour la t‚l‚
		bne.s	.vga_col
		or	#%000001000,d0
		bra.s	.vga_st
.vga_col
		cmp	#%100,d1
		bne.s	.vga_st
		and	#%110010111,d0
.vga_st
		btst	#7,d0
		beq.s	.mode_ok
		tst	d1
		beq.s	.vga_haute
		cmp	#1,d1
		beq.s	.vga_moy
.vga_basse
		move	#%110010010,d0
		bra.s	.mode_ok
.vga_moy
		move	#%110011001,d0
		bra.s	.mode_ok
.vga_haute
		move	#%010011000,d0
		bra.s	.mode_ok
.tv
		and	#%110001111,d0
		move	d0,d1
		and	#%111,d1
		bne.s	.tv_col
		or	#%000001000,d0
.tv_col
		btst	#7,d0
		beq.s	.mode_ok
		tst	d1
		beq.s	.tv_haute
		cmp	#1,d1
		beq.s	.tv_moy
.tv_basse
		move	#%110010010,d0
		bra.s	.mode_ok
.tv_moy
		move	#%110011001,d0
		bra.s	.mode_ok
.tv_haute
		move	#%010011000,d0
.mode_ok
		or	pal(pc),d0	;rajoute le bit pal
		
		move.l	(sp)+,d2
		move.l	(sp)+,d1
		rts

		*-------------------*

*-------------------------------------------------------------------------*
*	Sous-fonction pour le passage d'une nouvelle r‚solution
*-------------------------------------------------------------------------*

		*-------------------*
		* cfg_param: contient un pointeur sur une r‚solution
		* met a jour l'adresse ‚cran
		*-------------------*
		cnop	0,16
set_video
		movem.l	d0-7/a0-2,-(sp)

	* place l'‚cran
		move.l	#640*480/2,d0
		move.l	chip_top(a6),a0
		move.l	a0,a2
		sub.l	d0,a0
		
		lsr.l	#4+2,d0	;par paquets de 64 octets
		moveq	#0,d1
		move.l	d1,d2
		move.l	d1,d3
		move.l	d1,d4
.clr_chip
		rept	4
		movem.l	d1-4,-(a2)
		endr
		subq.l	#1,d0
		bne.s	.clr_chip

		move.l	a2,phys_adr
		pea	(a2)

		lea	$ffff8200.w,a0
		move.b	1(sp),1(a0)
		move.b	2(sp),3(a0)
		move.b	3(sp),$d(a0)
		move.l	(sp)+,_v_bas_ad.w

	* installation du mode vid‚o
		move.l	cfg_param(pc),a1

	* mode ‚tendu...
		lea	v_x(a1),a0
		move.l	a0,screen_param
		lea	v_videl(a1),a0
		move.l	a0,videl_param

	* PAF LE VIDEL!

		clr.b	$ffff8265.w
		clr.b	_SHIFT.w

		* synchro ext et pal
		cmp	#%10,monitor
		beq.s	.vga
		moveq	#%1,d0
		clr.b	ct2_reg+clk_32
		bra.s	.ext
.vga
		moveq	#0,d0
.ext
		tst	pal
		beq.s	.pas_pal
		or	#%10,d0
.pas_pal
		move.b	d0,$ffff820a.w

		* SpShift	(1)
		move	(a0)+,$ffff8266.w

		* Shift (2)
		move	(a0)+,d0
		beq.s	.pas_shift
		move.b	d0,$ffff8260.w
.pas_shift
		* VCO (3)
		move	(a0)+,$ffff82c0.w

		* Vmode) (4)
		move	(a0)+,$ffff82c2.w

		* Hxx
		lea	$ffff8282+8*2.w,a1	; tapons le gars VIDEL !
		movem.w	(a0)+,d0-d7
		movem.w	d0-d7,-(a1)

		* Vxx
		lea	$ffff82a2+6*2.w,a1
		movem.w	(a0)+,d0-d5
		movem.w	d0-d5,-(a1)

	* R‚solution...
		move.l	screen_param(pc),a0

		move	(a0)+,d0
		move	d0,phys_w
		move	(a0)+,phys_h
		move	(a0),d1
		move	d1,n_planes

	* offset
		mulu	d1,d0
		lsr	#4,d0

		move	d0,$ffff8210.w
		clr	$ffff820e.w

		*-------------*

		movem.l	(sp)+,d0-7/a0-2
		rts

		*-------------*

*-------------------------------------------------------------------------*

		*-------------*
		* installe une palette visible
		* modifie d0 et a0
		cnop	0,16
put_pal
		cmp	#1,n_planes
		beq.s	.fin
		
		move.l	a1,-(sp)

		*-------------*

		moveq	#1,d0
		lsl	d1,d0
		subq	#1,d0

		lea	$ffff9800.w,a0
		lea	palette(pc),a1
		moveq	#16-1,d0
.copie_pal
		move.l	(a1)+,(a0)+
		dbra	d0,.copie_pal

		*-------------*

		move.l	(sp)+,a1
.fin
		rts

		*-------------*

*-------------------------------------------------------------------------*
		DATA
*-------------------------------------------------------------------------*

		*-------------*

		cnop	0,16
video_list	dc.l	video_bin+v_len*0
		dc.l	video_bin+v_len*1
		dc.l	video_bin+v_len*2
		dc.l	video_bin+v_len*3
		
		cnop	0,16
video_bin		INCBIN	SVIDEO.BIN

		cnop	0,16
palette		INCBIN	SPALF030.DAT

		*-------------*

*-------------------------------------------------------------------------*
		BSS
*-------------------------------------------------------------------------*

		*-------------*

cfg_param		ds.l	1	;pointeur sur le mode en cours (0 sinon)

screen_param	ds.l	1	;pointeur sur les params ‚cran
videl_param	ds.l	1	;pointeur sur les params VIDEL


cur_mode		ds.w	1

phys_adr		ds.l	1	;adresse physique
phys_w		ds.w	1	;largeur phys
phys_h		ds.w	1	;hauteur phys
n_planes		ds.w	1	;nb de plan

monitor		ds.w	1	;type de moniteur connect‚ (copie du registre)
pal		ds.w	1	;flag pal

		*-------------*

*-------------------------------------------------------------------------*

