menu.c 7.7 KB
/*======================================================================*/
/*		NuSYS 64GBPak test sample				*/
/*		menu.c							*/
/*									*/
/*		Copyright (C) 1997, NINTENDO Co,Ltd.			*/
/*======================================================================*/  
#include <nusys.h>
#include "localdef.h"

extern Gfx*	gfxListPtr;
extern Gfx*	gfxListStartPtr;
extern void	gfxListBufferChange(void);
extern void	gfxClearCfb(u32 size);
extern NUContData contData[4];

extern void funccheck(s32 funcNo);

/*----------------------------------------------------------------------*/
/*  MENU用の文字列定義							*/
/*----------------------------------------------------------------------*/
struct st_menuList;

typedef struct st_menuLink {
    struct st_menuList **list;
} MenuLink;

typedef struct st_menuList {
    u8*			title;
    struct st_menuList*	next;
    s32			flag;
} MenuList;

MenuList funcTestPowerList[] = {
    {"64GBPack Power OFF", NULL, MENU_FUNCPOWER},
    {"64GBPack Power ON", NULL, MENU_FUNCPOWER},
    {NULL, NULL, 0}
};

MenuList funcTestList[] = {
    {"nuContGBPakOpen()", NULL, MENU_FUNCTEST},
    {"nuContGBPakGetStatus()", NULL, MENU_FUNCTEST},
    {"nuContGBPakPower()", funcTestPowerList, MENU_MODE},
    {"nuContGBPakReadID()", NULL, MENU_FUNCTEST},
    {"nuContGBPakRead()", NULL, MENU_FUNCTEST},
    {"nuContGBPakWrite()", NULL, MENU_FUNCTEST},
    {"nuContGBPakCheckConnector()", NULL, MENU_FUNCTEST},
    {"nuContGBPakFread()", NULL, MENU_FUNCTEST},
    {"nuContGBPakFwrite()", NULL, MENU_FUNCTEST},
    {"nuContGBPakRegWrite()", NULL, MENU_FUNCTEST},
    {NULL, NULL, 0}
};



MenuList* menuListPtr =  funcTestList;	/* 表示するメニューリスト	*/
MenuList* menuListPrev[4];		/* 選択したメニューの履歴	*/
u8	menuSel[8];
u8	menuDeps;			/* メニュー階層の深度		*/
s32	menuFlag;			/* メニュー表示制御用のフラグ	*/
s32	dispFlag;			/* 表示用のフラグ		*/

NUContPakFile	file[MAXCONTROLLERS];
s32		contNo = 0;
u8		gbpakInit[MAXCONTROLLERS] = {0, 0, 0, 0};
OSGbpakId	gbpakId[MAXCONTROLLERS];
u8		gbData[0x10000];



/*----------------------------------------------------------------------*/
/*	dispFrame - 画面の枠の表示					*/
/*	画面の枠を表示する。といってもテキスト文字で。			*/
/*	IN:	無し							*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void dispFrame(void)
{
    s32 cnt;

    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_LIGHTBLUE);
    nuDebConTextPos(NU_DEB_CON_WINDOW0, 1, 1);
    nuDebConCPuts(NU_DEB_CON_WINDOW0, " ==================================== ");
    nuDebConTextPos(NU_DEB_CON_WINDOW0, 12, 1);
    nuDebConCPuts(NU_DEB_CON_WINDOW0, "64GB Pack Test");

    for(cnt = 0; cnt < 26; cnt++){
	nuDebConTextPos(NU_DEB_CON_WINDOW0, 1, 2 + cnt);
	nuDebConCPuts(NU_DEB_CON_WINDOW0, "#");
	nuDebConTextPos(NU_DEB_CON_WINDOW0, 38, 2 + cnt);
	nuDebConCPuts(NU_DEB_CON_WINDOW0, "#");
    }
    nuDebConTextPos(NU_DEB_CON_WINDOW0, 1, 28);
    nuDebConCPuts(NU_DEB_CON_WINDOW0, " ==================================== ");
    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_WHITE);
    
}

/*----------------------------------------------------------------------*/
/*	dispMenu - メニューの表示					*/
/*	メニュー階層のうち、指定されているメニューのリストを表示する	*/
/*	IN:	無し							*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void dispMenu(void)
{
    s32 cnt;
  
    for(cnt = 0; menuListPtr[cnt].title != NULL; cnt++){
	if(cnt == menuSel[menuDeps]){
	    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_RED);
	    nuDebConTextPos(NU_DEB_CON_WINDOW0, 3, 3 + menuSel[menuDeps] * 2);
	    nuDebConCPuts(NU_DEB_CON_WINDOW0, ">");
	} else {
	    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_WHITE);
	}
	nuDebConTextPos(NU_DEB_CON_WINDOW0, 4, 3 + cnt * 2);
	nuDebConCPuts(NU_DEB_CON_WINDOW0, menuListPtr[cnt].title);
    }
}


/*----------------------------------------------------------------------*/
/*	dispFuncTest - 選択した関数をサブタイトルとして表示する		*/
/*	選択した関数の関数名をサブタイトル位置に,センタリングして表示する*/
/*	IN:	無し							*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void dispFuncTest(void)
{
    s32 len;
    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_GREEN);

    
    for(len = 0; menuListPtr[menuSel[menuDeps]].title[len] != '\0'; len++)
	;
    nuDebConTextPos(NU_DEB_CON_WINDOW0, 20-len/2, 3);
	
    nuDebConCPuts(NU_DEB_CON_WINDOW0, menuListPtr[menuSel[menuDeps]].title);
    nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_WHITE);
}

/*----------------------------------------------------------------------*/
/*	dispConsole - 画面表示の制御					*/
/*	現在の画面表示状態を認識して文字出力の制御をおこなう		*/
/*	IN:	無し							*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void dispConsole(u32 taskNum)
{
    gfxListBufferChange();
    gfxClearCfb(0);

        /* end top-level display list */
    gDPFullSync(gfxListPtr++);
    gSPEndDisplayList(gfxListPtr++);
    
    nuGfxTaskStart(gfxListStartPtr, gfxListPtr - gfxListStartPtr,
		   NU_GFX_UCODE_S2DEX,NU_SC_NOSWAPBUFFER);

    nuDebConDisp(NU_SC_SWAPBUFFER);
    nuDebConClear(NU_DEB_CON_WINDOW0);
    dispFrame();
    switch(dispFlag){
    case DISP_MENU:
	dispMenu();
	break;
    case DISP_FUNCTEST:
	dispFuncTest();
	break;
    case DISP_FUNCPOWER:
	nuDebConTextColor(NU_DEB_CON_WINDOW0, NU_DEB_CON_TEXT_GREEN);
	nuDebConTextPos(NU_DEB_CON_WINDOW0, 10, 3);
	nuDebConCPuts(NU_DEB_CON_WINDOW0, "nuContGBPakPower");
	break;
    case DISP_FUNCREADWRITE:
	break;
    case DISP_FUNCINPUTADDR:
	dispFuncTest();
	break;
    }
}

/*----------------------------------------------------------------------*/
/*	mainMenu - 入力処理						*/
/*	パッド入力をチェックしてメニューリストの制御処理をおこなう	*/
/*	IN:	無し							*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void mainMenu(void)
{

    
    if(contData[0].trigger & D_JPAD){
	if(menuListPtr[menuSel[menuDeps]+1].title != NULL){
	    menuSel[menuDeps]++;
	}
    }
    
    if(contData[0].trigger & U_JPAD){
	if(menuSel[menuDeps] > 0){
	    menuSel[menuDeps]--;
	}
    }
    if(contData[0].trigger & A_BUTTON){
	MenuList* nextListPtr;
	nextListPtr = menuListPtr[menuSel[menuDeps]].next;
	if(nextListPtr){
	    menuListPrev[menuDeps] = menuListPtr;
	    menuListPtr = nextListPtr;
	    menuDeps++;
	    menuSel[menuDeps] = 0;
	} else {
	    menuFlag = menuListPtr[menuSel[menuDeps]].flag;
	}
    }
    
    if(contData[0].trigger & B_BUTTON){
	if(menuDeps){
	    menuDeps--;
	    menuListPtr = menuListPrev[menuDeps];
	}
    }

}

/*----------------------------------------------------------------------*/
/*	メニュー操作の処理						*/
/*	IN:	特になし						*/
/*	RET:	無し							*/
/*----------------------------------------------------------------------*/
void menu(void)
{

    nuDebConScroll(NU_DEB_CON_WINDOW0, NU_DEB_CON_SCROLL_OFF);
    nuDebConWindowShow(NU_DEB_CON_WINDOW1, NU_DEB_CON_WINDOW_OFF);
    nuDebConWindowShow(NU_DEB_CON_WINDOW2, NU_DEB_CON_WINDOW_OFF);
    nuDebConWindowShow(NU_DEB_CON_WINDOW3, NU_DEB_CON_WINDOW_OFF);


    menuDeps = 0;
    menuFlag = MENU_MODE;
    dispFlag = DISP_MENU;
    nuGfxDisplayOn();
    nuGfxFuncSet(dispConsole);
    
    while(1){
	nuGfxRetraceWait(1);
	
	/* コントローラデータの読み込み */
	nuContDataGetExAll(contData);
	switch(menuFlag){
	case MENU_MODE:
	    dispFlag = DISP_MENU;
	    mainMenu();
	    break;
	case MENU_FUNCTEST:
	    dispFlag = DISP_FUNCTEST;
	    funccheck(menuSel[menuDeps]);
	    menuFlag = MENU_MODE;
	    break;
	case MENU_FUNCPOWER:
	    dispFlag = DISP_FUNCPOWER;
	    funccheck(menuSel[menuDeps-1]);
	    menuFlag = MENU_MODE;
	    menuDeps--;
	    menuListPtr = menuListPrev[menuDeps];
	    break;
	}
    }
}