*
*   refresh.s - refresh routines
*   Copyright (C) 1997 Aki Laukkanen
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program; if not, write to the Free Software Foundation,
*   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*

	XDEF    _evd_refresh
	XDEF    _vblank_interrupt

	include "exec/types.i"
	include "exec/interrupts.i"
	include "lvo/exec_lib.i"
	include "evd_context.i"
	include "shapeextvideo.i"

*
*   SYNOPSIS
*       ULONG __asm evd_refresh( register __a2 APTR);
*
*   FUNCTION
*

_evd_refresh
	tst.w   (ct_OwnRefresh,a2)
	bne     .end
	move.l  a2,a0
	move.l  (ct_C2P,a2),a1
	jsr     (a1)
	move.l  a6,-(sp)
	move.l  (ct_SysBase,a2),a6
	jsr     (_LVOSuperState,a6)
	pflusha
	jsr     (_LVOUserState,a6)
	move.l  (sp)+,a6
.end
	moveq   #EVD_OK,d0
	rts

_evd_vblank_refresh
	subq.w  #1,(ct_RefreshCnt,a1)
	bpl     .end
	move.w  (ct_RefreshRate,a1),(ct_RefreshCnt,a1)
	move.l  a1,a0
	move.l  (ct_C2P,a1),a1
	jsr     (a1)
	pflusha
.end
	moveq   #0,d0
	rts

_vblank_server
	addq.b  #1,_c2p_semaphore           ; Semaphore protection so we don't
										; trigger excessive amounts of
										; refresh ops.
	cmp.b   #1,_c2p_semaphore
	bne     .end

	bsr     _evd_vblank_refresh
;    move.l  (ct_SysBase,a1),a6
;    move.l  a1,a0
;    lea     _soft_interrupt,a1
;    move.l  a0,(IS_DATA,a1)
;    jsr     (_LVOCause,a6)

.end
	subq.b  #1,_c2p_semaphore
	moveq   #0,d0                       ; Z flag set
	rts

	section __MERGED,data

	cnop    0,4

_c2p_semaphore
	dc.l    0

_soft_interrupt
	dc.l    0
	dc.l    0
	dc.b    NT_INTERRUPT
	dc.b    0
	dc.l    _soft_name
	dc.l    0                   ; data
	dc.l    _evd_vblank_refresh

	cnop    0,4

_vblank_interrupt
	dc.l    0                   ; succ
	dc.l    0                   ; pred
	dc.b    NT_INTERRUPT        ; type
	dc.b    0                   ; pri
	dc.l    _vblank_name        ; name
	dc.l    0                   ; data
	dc.l    _vblank_server      ; code

_vblank_name
	dc.b    'TurboEVD vblank interrupt server',0

_soft_name
	dc.b    'TurboEVD soft interrupt',0
