testDriver.c 7.24 KB
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     Ported from Nintendo ZARU GNG Test

 :set tabstop=4
 
 Changed:  Delete all zaru related code

 To add the new test:
     Add the routine(return #of errors) in testlist.
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

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

extern void ssn(void);

extern int controllerSlot;

Test_t testList[] = {
    { 0, &(ContTest_bb)       ,"Controller test"                      ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexCONT  },
    { 0, &(rsp)            ,"RSP Diagnostic Tests"		             ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexRSP   },
    { 0, &(dlDriver)       ,"RDP Display List Checksum"            ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexRDP   },
    { 0, &(WaveOutput)     ,"Wave Output"                          ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexWAVE  },
    { 1, &(music44100)     ,"Music with 44100Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index441   },
    { 1, &(music32000)     ,"Music with 32000Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index320   },
    { 1, &(music22050)     ,"Music with 22050Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index220   },
    { 1, &(RunViTests)     ,"Video Patterns"					             ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexVIDEO },
};

int WaveOutput()
{
    char message[256];
    int length;
    
    length=SNDLENGTHDEFAULT;
    
    sprintf(message,"When press start,\nOutput sin wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_SINWAVE,length);
    
    sprintf(message,"When press start,\nOutput saw wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_SAWWAVE,length);
    
    sprintf(message,"When press start,\nOutput triangle wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_TRIWAVE,length);
    
    sprintf(message,"When press start,\nOutput rectangle wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_RCTWAVE,length);
    
    sprintf(message,"When press start,\nOutput sin wave\nonly Left channel");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_ONLYL,length);

    sprintf(message,"When press start,\nOutput sin wave\nonly Right channel");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    while (!GetTrigger());
    audioTest(ZARU_ONLYR,length);
    
    return GNG_TEST_SUCCESS;
}

void presstonext()
{
    char message[80];
    sprintf(message,"When press yellow button,\nGo next test.");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
}

int my_strcat(char *dst, const char *append)
{
    char *stmp = dst, *sadd=(char *) append;

    while (*stmp) stmp++;
    while (*sadd)
        *stmp++ = *sadd++;

    *stmp = '\0';
    return 0;
}

    /* Controller test for BB player */
int ContTest_bb() 
{
    int wait_to_start = 1, press_A_num=0, A_pressed=0;
    int buf_change=1, i;
    char pattern, msg[1024], sxy[64];
    OSContStatus     sdata[MAXCONTROLLERS];
    OSContPad        ctrl_data[MAXCONTROLLERS];
    u16              but, old_but[MAXCONTROLLERS], key;
    s8               stickX, old_stickX[MAXCONTROLLERS], 
                     stickY, old_stickY[MAXCONTROLLERS];
    
       /* assume siMessageQ are already created in mainproc() */
    osSetEventMesg(OS_EVENT_SI, &siMessageQ, (OSMesg)NULL);
    osContInit(&siMessageQ, &pattern, &sdata[0]);

    while (press_A_num < 3) {
        if (wait_to_start) {
            sprintf(msg,"BB Controller test\n\n\n\nPress start ...\n");
            if (buf_change) {
		        gng_report(msg,1,GNG_INHIBIT_PRINT,1);
                buf_change = 0;
	        }
        } else 
             sprintf(msg, "BB Controller test\n");

        osContStartReadData(&siMessageQ);
        osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
        osContGetReadData(ctrl_data);

        for (i=key=buf_change=0; i<MAXCONTROLLERS; i++) {
             but = ctrl_data[i].button;
             stickX = ctrl_data[i].stick_x & 0xff;
             stickY = ctrl_data[i].stick_y & 0xff;

             key |= but;
             buf_change |= (but != old_but[i]) || (old_stickY[i] != stickY) || (old_stickX[i] != stickX);
        }

        if (wait_to_start) {
            if (key & CONT_START) { 
                wait_to_start = 0;
                buf_change = 1;
                for (i=0; i<MAXCONTROLLERS; i++) {
					old_but[i] = but;
					old_stickX[i] = stickX;
					old_stickY[i] = stickY;
				}
            }
            continue;
        }
    
        if ( (A_pressed) && !(key & CONT_A) ) 
            press_A_num++;
        A_pressed = key & CONT_A;

        for (i=0; i<MAXCONTROLLERS; i++) {
            but = ctrl_data[i].button;
            stickX = ctrl_data[i].stick_x & 0xff;
            stickY = ctrl_data[i].stick_y & 0xff;
            if ( ctrl_data[i].errno != CONT_NO_RESPONSE_ERROR ) {
                if (i==0) my_strcat(msg, "LC: ");
                else {
					sprintf(sxy, "J%d:", i);
                    my_strcat(msg, sxy);
                }
                if (but & CONT_START) my_strcat(msg, " Start");
                if (but & CONT_A) my_strcat(msg, " A");
                if (but & CONT_B) my_strcat(msg, " B");
                if (but & CONT_G) my_strcat(msg, " G");
                if (but & CONT_L) my_strcat(msg, " L");
                if (but & CONT_R) my_strcat(msg, " R");
                if (but & CONT_E) my_strcat(msg, " E");
                if (but & CONT_C) my_strcat(msg, " C");
                if (but & CONT_F) my_strcat(msg, " F");
                if (but & CONT_D) my_strcat(msg, " D");
                if (but & CONT_UP) my_strcat(msg, " Up");
                if (but & CONT_DOWN) my_strcat(msg, " Down");
                if (but & CONT_LEFT) my_strcat(msg, " Left");
                if (but & CONT_RIGHT) my_strcat(msg, " Right");
                if (but) my_strcat(msg, "  pressed");

                sprintf(sxy, "\n  x=%d, y=%d\n", stickX, stickY);
                my_strcat(msg,  sxy);
            }
            old_but[i] = but;
            old_stickX[i] = stickX;
            old_stickY[i] = stickY;
        }
        my_strcat(msg, "\n\nPress A 3 times to quit");

        if (buf_change) {
            gng_report(msg,1,GNG_INHIBIT_PRINT,1);
            buf_change = 0;
        } 
    } 
    
    return GNG_TEST_SUCCESS;
}

void testDriver() 
{
    int i;
    int errCount=0, total;
    char message[256];

    total = sizeof(testList)/sizeof(Test_t);
#if CONTROLLER_TEST_ONLY
    ContTest_bb();    
#else
    for (i=0; i<total; i++) {
	errCount += testList[i].pTestFunction();
    }

    sprintf(message,"GNG Test Report \n Total number=%d \nFailed case=%d",
          total, errCount);
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
#endif
  
   
    return;
}