カウントダウンモードを実装。
既に作ってあったストップウォッチモード(カウントアップ)をリファイン。
なのでサクっと出来上がり。
本来のシュウォッチとしての機能はこれで全て実装終了。
次はスプライトと BG を本ちゃんに差し替えようかと。
CntdnMode.h
/*--------------------------------------------------------------------------------- shtwatch cntdnMode module header version 0.01 Feb 10, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _CNTDN_MODE_H_ #define _CNTDN_MODE_H_ #ifdef __cplusplus extern "C" { #endif void CntdnMode_Clear(void); void CntdnMode_Update(void); bool CntdnMode_IsExit(void); #ifdef __cplusplus } #endif #endif //_CNTDN_MODE_H_
CntdnMode.c
/*--------------------------------------------------------------------------------- shtwatch cntdnMode module routine version 0.01 Feb 10, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <stdio.h>//debug print #include <string.h> #include <nds/ndstypes.h> #include <nds/arm9/input.h> #include "CntdnMode.h" #include "Spr.h" typedef enum{ CNTDN_MODE_INIT = 0, CNTDN_MODE_READY, CNTDN_MODE_EXEC, CNTDN_MODE_EXIT }CNTDN_MODE_ACT; typedef struct{ u16 act; int type; int frame; int second; int minute; }CntdnModeStatus; static CntdnModeStatus st_cntdn_mode; void cntdnMode_Init(void); void cntdnMode_Ready(void); void cntdnMode_Exec(void); void cntdnMode_Exit(void); void cntdnMode_ReadyType(void); void cntdnMode_ClearType(void); void cntdnMode_DrawType(void); void cntdnMode_ExecCount(void); void cntdnMode_ClearCount(void); void cntdnMode_DrawCount(void); //--------------------------------------------------------------------------------- void CntdnMode_Clear(void){ //--------------------------------------------------------------------------------- cntdnMode_Exit(); } //--------------------------------------------------------------------------------- void CntdnMode_Update(void){ //--------------------------------------------------------------------------------- switch(st_cntdn_mode.act){ case CNTDN_MODE_INIT: cntdnMode_Init(); break; case CNTDN_MODE_READY: cntdnMode_Ready(); break; case CNTDN_MODE_EXEC: cntdnMode_Exec(); break; case CNTDN_MODE_EXIT: cntdnMode_Exit(); break; } } //--------------------------------------------------------------------------------- void cntdnMode_Init(void){ //--------------------------------------------------------------------------------- memset(&st_cntdn_mode, 0, sizeof(st_cntdn_mode)); Spr_SetColon(3); Spr_SetCursor(BIT(2)); cntdnMode_ClearType(); cntdnMode_ClearCount(); st_cntdn_mode.act = CNTDN_MODE_READY; } //--------------------------------------------------------------------------------- void cntdnMode_Ready(void){ //--------------------------------------------------------------------------------- if( (keysDown() & KEY_B) && ( (keysCurrent() & ~KEY_B) == 0) ){ cntdnMode_ReadyType(); cntdnMode_ClearCount(); } if( (keysDown() & KEY_A) && ( (keysCurrent() & ~KEY_A) == 0) ){ st_cntdn_mode.act = CNTDN_MODE_EXEC; } if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){ st_cntdn_mode.act = CNTDN_MODE_EXIT; } } //--------------------------------------------------------------------------------- void cntdnMode_Exec(void){ //--------------------------------------------------------------------------------- cntdnMode_ExecCount(); if( (keysDown() & KEY_A) && ( (keysCurrent() & ~KEY_A) == 0) ){ cntdnMode_ClearCount(); st_cntdn_mode.act = CNTDN_MODE_READY; } if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){ st_cntdn_mode.act = CNTDN_MODE_EXIT; } } //--------------------------------------------------------------------------------- void cntdnMode_Exit(void){ //--------------------------------------------------------------------------------- printf("\x01b[2J");//debug print Spr_Clear(); st_cntdn_mode.act = CNTDN_MODE_INIT; } //--------------------------------------------------------------------------------- void cntdnMode_ReadyType(void){ //--------------------------------------------------------------------------------- if(st_cntdn_mode.type == 2){ st_cntdn_mode.type = 3; }else if(st_cntdn_mode.type == 3){ st_cntdn_mode.type = 5; }else{// if(st_cntdn_mode.type == 5){ st_cntdn_mode.type = 2; } cntdnMode_DrawType(); } //--------------------------------------------------------------------------------- void cntdnMode_ClearType(void){ //--------------------------------------------------------------------------------- st_cntdn_mode.type = 2; cntdnMode_DrawType(); } //--------------------------------------------------------------------------------- void cntdnMode_DrawType(void){ //--------------------------------------------------------------------------------- printf("\x01b[9;7H%2d", st_cntdn_mode.type);//debug print Spr_SetNumber(SEG_SECOND, st_cntdn_mode.type, false); } //--------------------------------------------------------------------------------- void cntdnMode_ExecCount(void){ //--------------------------------------------------------------------------------- if(st_cntdn_mode.frame == 0 && st_cntdn_mode.second == 0 && st_cntdn_mode.minute == 0) return; //1/60秒 if(st_cntdn_mode.frame > 0){ st_cntdn_mode.frame--; }else{ //秒 if(st_cntdn_mode.second > 0){ st_cntdn_mode.second--; st_cntdn_mode.frame = 60; }else{ //分 if(st_cntdn_mode.minute > 0){ st_cntdn_mode.minute--; st_cntdn_mode.second = 60; } } } cntdnMode_DrawCount(); } //--------------------------------------------------------------------------------- void cntdnMode_ClearCount(void){ //--------------------------------------------------------------------------------- st_cntdn_mode.frame = 60; st_cntdn_mode.second = 0; st_cntdn_mode.minute = st_cntdn_mode.type; cntdnMode_DrawCount(); } //--------------------------------------------------------------------------------- void cntdnMode_DrawCount(void){ //--------------------------------------------------------------------------------- //debug print printf("\x01b[9;0H %2d:%02d ", st_cntdn_mode.minute, st_cntdn_mode.second); Spr_SetNumber(SEG_MINUTE, st_cntdn_mode.second, true); Spr_SetNumber(SEG_HOUR, st_cntdn_mode.minute, false); } //--------------------------------------------------------------------------------- bool CntdnMode_IsExit(void){ //--------------------------------------------------------------------------------- return (st_cntdn_mode.act == CNTDN_MODE_INIT) ? true:false; } //---------------------------------------------------------------------------------