uji.c 4.22 KB
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1995, 1996 Silicon Graphics, Inc.          *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

#include <ultra64.h>
#include "gng.h"

/*
 * File:	uji.c
 * Creator:	scott@sgi.com
 * Purpose:	Ported code, from uji_diags.c, for tests that require 
 *		the Zaru jig.
 */

static u8 controllerdata[] = {
    0x00, 
    0x55, 
    0xaa, 
    0xff, 
    0x01, 
    0x02, 
    0x04, 
    0x08, 
    0x10, 
    0x20, 
    0x40, 
    0x80, 
};

/*
 * Check the power, ground, and other signal bits.
 * These are scattered around in the zaru address space
 */
int
VoltageTest()
{
    int retvalue = GNG_TEST_SUCCESS;	    /* assume success */
    u8 data;

#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
	return GNG_TEST_SUCCESS;
#endif
    
    /* First check the Power line register (0x1800) */
    data = ZaruGetPowerCheck();

    /*
     * check that only the bits that should be on are on
     * and that only those bits are on.
     */
    if (data ^ (ZARU_V2 | ZARU_V3 | ZARU_V4 | ZARU_GND1CHK | ZARU_GND2CHK))
	retvalue = GNG_TEST_FAILURE;
	
    data = ZaruGetMisc();
    if ( (data & ZARU_MISC_5VCHKCON) == 0)
	retvalue = GNG_TEST_FAILURE;

    ZaruSetExpCommand(ZARU_EXP_CMD_GND);
    
    data = ZaruGetExpHigh();
    /*
     * check that only the bits that should be on are on
     * and that only those bits are on.
     * XXXX - also checking SEC1, SEC2,  CCLK & CSYNC
     */
    if (data ^ (ZARU_SEC1 | ZARU_SEC2 | ZARU_CCLK | ZARU_CSYNC))
	retvalue = GNG_TEST_FAILURE;
    
    data = ZaruGetExpLow();
    /*
     * check that only the bits that should be on are on
     * and that only those bits are on.
     */
    if (data)
	retvalue = GNG_TEST_FAILURE;
	
    ZaruSetExpCommand(ZARU_EXP_CMD_VOLT);
    data = ZaruGetExpLow();
    data &= (ZARU_12V1 | ZARU_3V0 | ZARU_3V1 | ZARU_3V2);   /* some bits unused!!! */
    /*
     * check that only the bits that should be on are on
     * and that only those bits are on.
     */
    if (data ^ (ZARU_12V1 | ZARU_3V0 | ZARU_3V1 | ZARU_3V2))
	retvalue = GNG_TEST_FAILURE;
    
    return retvalue;
}

/*
 * Check that the reset time is in acceptable range
 */
int
ResetTimeTest()
{
    int resettime;
    
#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
	return GNG_TEST_SUCCESS;
#endif
    
    resettime = ZaruGetResetTime();
    
    if (resettime >= ZARU_RESET_LOW && resettime <= ZARU_RRESET_HIGH)
	return GNG_TEST_SUCCESS;
    else
	return GNG_TEST_FAILURE;
}

/*
 * Test Joy ports 2, 3, and 4
 * There is only one switch register.  You cannot write different
 * data values to 2, 3, and 4 and then expect those values to be
 * read back.  Only the data from the last write is available.
 */
int
ControllerTest()
{
    u16 buttons;
    u8 select;
    int i, j;

#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
	return GNG_TEST_SUCCESS;
#endif
    
    /*
     * test joy ports 2, 3, and 4.  Remember that a Fortran progammer
     * labled the connectors.
     */
    for (i = 1; i< 4; i++) {
	switch (i) {
	  case 1:
	    select = ZARU_JOY_SELECT_2;
	    break;
	    
	  case 2:
	    select = ZARU_JOY_SELECT_3;
	    break;
	    
	  case 3:
	    select = ZARU_JOY_SELECT_4;
	    break;
	}
	
	ZaruSetJoySelect(select);
	for (j = 0; j < sizeof(controllerdata)/sizeof(u8); j++) {
	    ZaruSetJoyButtons(controllerdata[j]);
	    if (ZaruButtonCheck(controllerdata[j], ZaruReadControllerButton(i))
		    == GNG_TEST_FAILURE) {
		    
		return GNG_TEST_FAILURE;
	    }
	}
    }
 
    return GNG_TEST_SUCCESS;
}