ulxmain.c 10.4 KB
/*
 *  F i l e N a m e  :  U L X M A I N . C
 *
 ****************************************************************************
 *                   (C) CopyRight ALPS Electric Co., Ltd. 1996
 ****************************************************************************
 *  Version
 *
 *  ver     Date
 *  ----  --------
 *  1.10  '97,03,10  Update version (3.31 -> 3.31a) add disk in switch test
 *  1.10  '97,03,10  Update version (     -> 3.30)
 *  1.03  '96.10.12  Update version (3.02 -> 3.02A).
 *  1.02  '96.07.17  Add LIFE-TEST Menu.
 *  1.01  '96.02.05  ベンチマーク測定メニューを追加
 *  1.00  '95.12.20  Initial revision .
 ****************************************************************************
*/
/*===========================================*/
/* レオドライブ用テストソフトのメインルーチン                 */
/*===========================================*/

#include <ultra64.h>
#include "ulxlib.h"
#include "ulxutil.h"

#include "leodrive.h"

#define CONTINUE    0
#define ENABLE      1
#define DISABLE     0

u32 min_lba    = LEO_LBA_MIN;
u32 max_lba    = LEO_LBA_MAX;
u32 test_blk   = 2;
u8  rnd_blk    = DISABLE;
u8  rnd_data   = DISABLE;
u8  tag_data   = DISABLE;
u32 pass_count = CONTINUE;
u8  err_stop   = ENABLE;
u8  disktype   = 0;
u8  cmpflg     = ENABLE;
u8  dispflg    = ENABLE;

u8  notdisp    = 0;
u32 err_count  = 0;

void LeoulxMain( void *arg );
void bufhandle(void);
void init_display(void);
void MakeSystemData(void);

extern void commandtest( void ) ;
extern void rwtest( void ) ;
extern void bench_test( void );
extern void life_test( void );

/*********************************************************/
/* DEFINITION                                            */
/*********************************************************/

OSMesgQueue  serialMessageQ;
OSMesgQueue  controllerMessageQ;
OSMesg       serialMsgBuf;
OSMesg       controllerMsgBuf;
OSContStatus statusdata[MAXCONTROLLERS];
OSContPad    controllerdata[MAXCONTROLLERS];
char         *staticSegment;

#define LEOULX_STACKSIZE 2048
OSThread leoulxThread;
u64 leoulxStack[LEOULX_STACKSIZE/sizeof(u64)];

extern union data_trans_form LEO_country_code;
extern u32   draw_string( char *);
extern s8    LEOfirmware_rev[];

const u8 *SC_NAME_SHORT[] = 
{   "NO SENSE           ",
    "DRIVE NOT READY    ",
    "DIAG ERROR         ",
    "COMMAND PHASE ERR  ",
    "DATA PHASE ERR     ",
    "RTC  FAILURE       ",
    "06 UNKNOWN ERR     ",
    "07 UNKNOWN ERR     ",
    "08 UNKNOWN ERR     ",
    "09 UNKNOWN ERR     ",
    "10 UNKNOWN ERR     ",
    "INCOMPATIBLE MEDIUM",
    "12 UNKNOWN ERR     ",
    "13 UNKNOWN ERR     ",
    "14 UNKNOWN ERR     ",
    "15 UNKNOWN ERR     ",
    "16 UNKNOWN ERR     ",
    "17 UNKNOWN ERR     ",
    "18 UNKNOWN ERR     ",
    "19 UNKNOWN ERR     ",
    "20 UNKNOWN ERR     ",
    "NO SEEK COMP       ",
    "WRITE FAULT        ",
    "UNRECOVERD READ ERR",
    "NO REFERENCE POS   ",
    "TRACK FOLLOWING ERR",
    "26 UNKNOWN ERR     ",
    "27 UNKNOWN ERR     ",
    "28 UNKNOWN ERR     ",
    "29 UNKNOWN ERR     ",
    "30 UNKNOWN ERR     ",
    "INVALID CMD        ",
    "LBA OUT OF RANGE   ",
    "WRITE PROTECTED    ",
    "COMMAND TERMINATED ",
    "QUEUE FULL         ",
    "ILLEGAL TIMER VALUE",
    "37 UNKNOWN ERR     ",
    "38 UNKNOWN ERR     ",
    "39 UNKNOWN ERR     ",
    "40 UNKNOWN ERR     ",
    "COMMUNICATION ERR  ",
    "MEDIUM NOT PRESENT ",
    "RESET OCCURRED     ",
    "44 UNKNOWN ERR     ",
    "45 UNKNOWN ERR     ",
    "46 UNKNOWN ERR     ",
    "MEDIUM CHANGED     ",
    "48 UNKNOWN ERR     ",
    "EJECTED            ",
    "50 UNKNOWN ERR     ",
    "EJECTED            "
};

/*==========================================================*/
void start(void)
{
    init_display();

    osCreateThread(&leoulxThread,(OSId)7,LeoulxMain,(void*)0,
	leoulxStack+LEOULX_STACKSIZE/sizeof(u64),(OSPri)40);
    osStartThread(&leoulxThread);
    while(1)osYieldThread();

}

void init_display(void)
{
    osViModeTable[OS_VI_NTSC_LPN1].comRegs.hStart=
        (((((osViModeTable[OS_VI_NTSC_LAN1].comRegs.hStart>>16)&0xffff)-24)%0xffff)<<16)|
        (((((osViModeTable[OS_VI_NTSC_LAN1].comRegs.hStart>> 0)&0xffff)-24)%0xffff)<< 0);
    osViModeTable[OS_VI_NTSC_LPN1].fldRegs[0].vStart=
        (((((osViModeTable[OS_VI_NTSC_LAN1].fldRegs[0].vStart>>16)&0xffff)-6)%0xffff)<<16)|
        (((((osViModeTable[OS_VI_NTSC_LAN1].fldRegs[0].vStart>> 0)&0xffff)-6)%0xffff)<< 0);
    osViModeTable[OS_VI_NTSC_LPN1].fldRegs[1].vStart=
        (((((osViModeTable[OS_VI_NTSC_LAN1].fldRegs[1].vStart>>16)&0xffff)-6)%0xffff)<<16)|
        (((((osViModeTable[OS_VI_NTSC_LAN1].fldRegs[1].vStart>> 0)&0xffff)-6)%0xffff)<< 0);
    osWritebackDCacheAll();
    osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
    *(u32*)PHYS_TO_K1(VI_H_VIDEO_REG)=0;
}

extern u16 key;

void    LeoulxMain(void *arg)
{

    u16 x_l=5, y_l=2, num=1;
    u16 col_l=5;
    u8  *left_d[10] = {"COMMAND TEST          ",
                       "WRITE/READ TEST       ",
                       "BENCHMARK TEST        ",
                       "LIFE TEST             ",
                       "VERSION               ",
                     };

    InitialRoutine();

beginulx:

#if 1 /* sw test */

    SCode = 43;

for (;;){
    u32 cnt,testmode;u8*modename[]={"READ","WRITE","READ/WAIT","WRITE/WAIT"};
    ClrDisp();
    ulxPrint0(0,0,CYAN,"DISK-IN SENSOR Test ");
    for (testmode = 0;;)
    {
      ulxPrint1(1,2,GREEN,"Select Test Mode: %s        ",modename[testmode]);
      key = InCtrlData();
      if ( key == CONT_START) break;
      if ( key == CONT_B)     break;
      if ( key == CONT_A) testmode += 1;
      if (testmode > 3) testmode = 0;
    }
    if ( key == CONT_B)     break;
    for (cnt = 0; ;cnt++)
    {
        switch (SCode)
        {
            case 43:  /* reset */
                ClrUAReset();
                ReadCapa(1,0,0);
                break;
            case 47:  /* medium change */
                ReadDiskID(RDB);
                ReadCapa(1,0,0);
            default:;
        }
        switch (testmode)
        {
            case 0:
            case 2:
                ulxPrint2( 1,4,GREEN,"READ  LBA=%u %u        ",TAG09.start_lba,cnt);
                ReadDrive(TAG09.start_lba,1,RDB);
                break;
            case 1:
            case 3:
                ulxPrint2( 1,4,GREEN,"WRITE LBA=%u %u       ",TAG09.start_lba,cnt);
                WriteDrive(TAG09.start_lba,1,RDB);
                break;
        }
        ulxPrint1( 3,6,GREEN,"%02d ",SCode);
        ulxPrint0( 6,6,GREEN,(u8*)SC_NAME_SHORT[SCode]);
        key = InCtrlData();
        switch (testmode)
        {
            case 2:
            case 3:
                for (;;)
                {
                    TestUnit();
                    if (TAG03.test & LEO_TEST_UNIT_SS)
                    {
                        ulxPrint0( 1,8,GREEN,"TEST UNIT READY  SLEEP   ");
                    }
                    else if (TAG03.test & LEO_TEST_UNIT_RE)
                        ulxPrint0( 1,8,GREEN,"TEST UNIT READY  STBY       ");
                    else
                        ulxPrint0( 1,8,GREEN,"TEST UNIT READY  ACTIV      ");
                    ulxPrint1( 3,10,GREEN,"%02d ",SCode);
                    ulxPrint0( 6,10,GREEN,(u8*)SC_NAME_SHORT[SCode]);
                    key = InCtrlData();
                    switch (key)
                    {
                        case CONT_A:
                        case CONT_B:
                        case CONT_START:
                            break;
                        default:
                            continue;
                    }
                    break;
                }
                break;
        }
        if ( key == CONT_B) break;
    }
    ulxPrint0( 1,8,GREEN,"Hit any key                    ");
    GetChr();
}
#endif  /* end of sw test */

    do
    {
        ClrDisp();
        Disp_Ready(0, 0, CYAN);
        sprintf( STR, "LEO TEST PROGRAM  LEOULX Ver.3.31a" );
        Disp_Fin();

        ListDisp( x_l, y_l, col_l, left_d, 0, 0, 0, (void *)0, GREEN );
        num = SelStr1( x_l, y_l, col_l, left_d, 1, GREEN );

        switch( num )
        {
            case 1:
                commandtest();
                break;
            case 2:
                rwtest();
                break;
            case 3:
                bench_test();
                break;
            case 4:
		life_test();
		break;
            case 5:
                ClrDisp();
                Disp_Ready( 7, 8, YELLOW);
                sprintf( STR, "VERSION      : %s",LEOfirmware_rev );
                Disp_Fin();
                Disp_Ready( 7, 9, YELLOW);
                if (LEO_country_code.u32_data == 0)
                    sprintf( STR, "COUNTRY CODE : DEVELOPER" );
                else
                    sprintf( STR, "COUNTRY CODE : MASS PRO." );
                Disp_Fin();
                GetChr();
                break;

            case ESC:
                goto beginulx;

            default:
                break;
        }

    } while( 1 );
    ClrDisp();
}

void    bufhandle( void )
{
    u32 pattern=0;
    u32 dwd;

    u16 x_l=5, y_l=2, col_l=7, num=1;
    u8  *left_d[9] = {"EDIT READ DATA BUFFER  ",
                      "EDIT WRITE DATA BUFFER ",
                      "CMP. R/W DATA BUFFER   ",
                      "SWAP R/W DATA BUFFER   ",
                      "CLEAR R/W DATA BUFFER  ",
                      "RND DATA PATTERN  <WDB>",
                      "FILL DATA PATTERN <WDB>"
                     };

    do
    {
        ClrDisp();
        Disp_Ready(0, 0, CYAN);
        sprintf( STR, "BUFFER EDIT MENU " );
        Disp_Fin();

        ListDisp( x_l, y_l, col_l, left_d, 0, 0, 0, (void *)0, GREEN );
        num = SelStr1( x_l, y_l, col_l, left_d, 1, GREEN );

        switch( num )
        {
            case 1:
                EditBuf( RDB, "EDIT READ BUFFER" );
                break;
            case 2:
                EditBuf( WDB, "EDIT WRITE BUFFER" );
                break;
            case 3:
                CompBufDisp();
                break;
            case 4:
                SwapBuf();
                break;
            case 5:
                ClrBuf();
                break;
            case 6:
                MakeRand( WDB, BUFSIZE );
                break;
            case 7:
                pattern = InDig32( pattern, 10, 10, YELLOW );
                for(dwd=0; dwd<(BUFSIZE/4); dwd++)
                {
                    ((u32 *)WDB)[dwd] = (u32)pattern;
                }
                break;
            default:
                break;
        }
    } while( num != ESC );
}