vi.c 4.36 KB

/*====================================================================
 * vi.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

/**************************************************************************
 *
 *  $Revision: 1.1.1.2 $
 *  $Date: 2002/10/29 08:06:43 $
 *  $Source: /root/leakn64/depot/rf/sw/bbplayer/libultra/monegi/vi/vi.c,v $
 *
 **************************************************************************/


#include "osint.h"
#include "rcp.h"
#include "viint.h"
#include "assert.h"


/***************************************************************************
 *
 * Design:
 *	There are 2 pointers to __osViContext structure: one to the current
 *	mode of current field and the other to the mode of the next field. 
 *	We simply swap these 2 pointers after a vertical retrace interrupt. 
 *	There are also VI state variables to track what special
 *	features have been enabled/disabled.
 *	The goal is to allow the user to modify the "next" VI context (i.e.,
 *	mode, x-scale, y-scale) - as often as he wishes - up until the vertical
 *	retrace interrupt which is when osViSwapBuffer() is called to update
 *	the HW registers with data from "next".
 *
 * Note:
 *   All osVixxx functions simply manipulate internal VI structure.
 *   Only the __osViSwapBuffer() routine actually programs the VI registers.
 *
 ***************************************************************************/


/**************************************************************************
 *
 * Defines
 */


/**************************************************************************
 *
 * Static variables
 */

static __OSViContext vi[2]	= {0};


/**************************************************************************
 *
 * Global variables
 */
__OSViContext *__osViCurr	= &vi[VI_FIELD1];
__OSViContext *__osViNext	= &vi[VI_FIELD2];

/*
int osViClock = VI_NTSC_CLOCK;	Now this value defined in osIniitialize 
*/

/**************************************************************************
 *
 * External declarations
 */


/**************************************************************************
 *
 * Functions
 */

/*
 * Name:   __osViInit
 *
 * Description:
 *	Initialize all VI global data structures with default values.
 *	This routine is called by osInitialize().
 *
 * Globals Referenced: 
 *	osTvType, vi, __osViCurr, __osViNext
 */
void
__osViInit(void)
{
    /*
     * Since this routine is called only once by osInitialize(), we don't
     * need to worry about protecting the global VI context array.
     */

    /* Zero out the 2 VI context structures */
    bzero((void *)vi, sizeof(vi));

    /* Initialize the 2 context pointers */
    __osViCurr = &vi[VI_FIELD1];
    __osViNext = &vi[VI_FIELD2];

    __osViNext->retraceCount = 1;
    __osViCurr->retraceCount = 1;

    __osViNext->framep = 0x80000000;
    __osViCurr->framep = 0x80000000;

    /* Initialize the default VI mode which is 
     *		LAN1: lo-res, anti-aliased, non-interlaced, 16-bit
     */
    if (osTvType == OS_TV_PAL)
      __osViNext->modep = &osViModePalLan1;
    else if (osTvType == OS_TV_MPAL)
      __osViNext->modep = &osViModeMpalLan1;
    else  /* for now, we assume that it's NTSC */
      __osViNext->modep = &osViModeNtscLan1;

    __osViNext->state	= (VI_STATE_NORMAL | VI_STATE_BLACK);
    __osViNext->control = __osViNext->modep->comRegs.ctrl;

    /* Spin until we are in the pre-blank stage */
    while (IO_READ(VI_CURRENT_REG) > 10);

    /* Zero out control register so that NMI reset to LAN1 is safe */
    IO_WRITE(VI_CONTROL_REG,	0);	/* Turn off video, reset counters */

    /* Update hardware register to start receiving vsync */
    __osViSwapContext();

}  /* __osViInit */