読者です 読者をやめる 読者になる 読者になる

ハートに16連射。(13)


ウォッチモードです。
スプライト描画サンプルを焼き直しして楽をしてます。


ビルドには下記ソース以外に、
「ハートに16連射。(12)」に記した全てのモジュールが必要だったり…。


ハートに16連射。(12)
http://d.hatena.ne.jp/dumbo001/20100201/p1


timeMode module test


main.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	timeMode module test
	
	version 0.01
	Feb 01, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <string.h>
#include <nds/ndstypes.h>
#include <nds/interrupts.h>
#include <nds/system.h>
#include <nds/arm9/input.h>
#include "Bg.h"
#include "Spr.h"
#include "TimeMode.h"


typedef enum{
	MAIN_INIT, 
	MAIN_RESET, 
	MAIN_EXEC
}MAIN_ACT;

typedef struct{
	u16 act;
}MainStatus;

static MainStatus st_main;


void main_Init(void);
void main_Reset(void);
bool main_IsReset(void);


//---------------------------------------------------------------------------------
int main(void){
//---------------------------------------------------------------------------------
	
	lcdSwap();
	
	while(1) {
		swiWaitForVBlank();
		scanKeys();
		
		Spr_Update();
		
		if(main_IsReset()){
			st_main.act = MAIN_RESET;
		}
		
		switch(st_main.act){
			
		case MAIN_INIT:
			main_Init();
			st_main.act = MAIN_RESET;
			break;
			
		case MAIN_RESET:
			main_Reset();
			st_main.act = MAIN_EXEC;
			break;
			
		case MAIN_EXEC:
			TimeMode_Update();
			
			if(TimeMode_IsExit()){
				return 0;
			}
			break;
			
		}
		
	}
	
}

//---------------------------------------------------------------------------------
void main_Init(void){
//---------------------------------------------------------------------------------
	
	memset(&st_main, 0, sizeof(st_main));
	Bg_Init();
	Spr_Init();
	
	Bg_DrawConsString(0, 0, "timeMode module test\n\nversion 0.01\nFeb 01, 2010\n\nBy. REGEKATSU\n\n\n");
	
}

//---------------------------------------------------------------------------------
void main_Reset(void){
//---------------------------------------------------------------------------------
	
	TimeMode_Clear();
	
}

//---------------------------------------------------------------------------------
bool main_IsReset(void){
//---------------------------------------------------------------------------------
	
	bool ans = false;
	
	u32 keys;
	
	if(keysDown() & (KEY_L | KEY_R | KEY_SELECT | KEY_START)){
		
		keys = keysDown() | keysHeld();
		keys = keys & (KEY_L | KEY_R | KEY_SELECT | KEY_START);
		
		if(keys == (KEY_L | KEY_R | KEY_SELECT | KEY_START)){
			ans = true;
		}
		
	}
	
	return ans;
	
}

//---------------------------------------------------------------------------------


timeMode.h

/*---------------------------------------------------------------------------------
	
	shtwatch
	timeMode module header
	
	version 0.01
	Feb 01, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _TIME_MODE_H_
#define _TIME_MODE_H_


#ifdef __cplusplus
extern "C" {
#endif


void TimeMode_Clear(void);
void TimeMode_Update(void);
bool TimeMode_IsExit(void);


#ifdef __cplusplus
}
#endif

#endif	//_TIME_MODE_H_


timeMode.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	timeMode module routine
	
	version 0.01
	Feb 01, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <stdio.h>//debug print
#include <string.h>
#include <nds/ndstypes.h>
#include <nds/arm9/input.h>
#include "TimeMode.h"
#include "Spr.h"
#include "Rtc.h"


typedef enum{
	TIME_MODE_INIT, 
	TIME_MODE_EXEC, 
	TIME_MODE_EXIT
}TIME_MODE_ACT;

typedef struct{
	
	u16 act;
	
	int sec_old;
	int sec_now;
	int min_old;
	int min_now;
	int hour_old;
	int hour_now;
	
}TimeModeStatus;

static TimeModeStatus st_time_mode;


void timeMode_Init(void);
void timeMode_Exec(void);
void timeMode_Exit(void);


//---------------------------------------------------------------------------------
void TimeMode_Clear(void){
//---------------------------------------------------------------------------------
	
	timeMode_Exit();
	
}

//---------------------------------------------------------------------------------
void TimeMode_Update(void){
//---------------------------------------------------------------------------------
	
	switch(st_time_mode.act){
		
	case TIME_MODE_INIT:
		timeMode_Init();
		break;
		
	case TIME_MODE_EXEC:
		timeMode_Exec();
		break;
		
	case TIME_MODE_EXIT:
		timeMode_Exit();
		break;
		
	}
	
}

//---------------------------------------------------------------------------------
void timeMode_Init(void){
//---------------------------------------------------------------------------------
	
	memset(&st_time_mode, 0, sizeof(st_time_mode));
	
	Spr_SetColon(3);
	Spr_SetCursor(BIT(1));
	
	st_time_mode.act = TIME_MODE_EXEC;
	
}

//---------------------------------------------------------------------------------
void timeMode_Exec(void){
//---------------------------------------------------------------------------------
	
	st_time_mode.sec_old = st_time_mode.sec_now;
	st_time_mode.min_old = st_time_mode.min_now;
	st_time_mode.hour_old = st_time_mode.hour_now;
	
	st_time_mode.sec_now = Rtc_GetSecond();
	st_time_mode.min_now = Rtc_GetMinute();
	st_time_mode.hour_now = Rtc_GetHour();
	
	if(st_time_mode.sec_old != st_time_mode.sec_now){
		
		//debug print
		printf("\x01b[9;0H %2d:%02d:%02d", 
			st_time_mode.hour_now, 
			st_time_mode.min_now, 
			st_time_mode.sec_now);
		
		Spr_SetNumber(SEG_SECOND, st_time_mode.sec_now, true);
		Spr_SetNumber(SEG_MINUTE, st_time_mode.min_now, true);
		Spr_SetNumber(SEG_HOUR, st_time_mode.hour_now, false);
		
	}
	
	if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){
		st_time_mode.act = TIME_MODE_EXIT;
	}
	
}

//---------------------------------------------------------------------------------
void timeMode_Exit(void){
//---------------------------------------------------------------------------------
	
	Spr_Clear();
	st_time_mode.act = TIME_MODE_INIT;
	
}

//---------------------------------------------------------------------------------
bool TimeMode_IsExit(void){
//---------------------------------------------------------------------------------
	
	return (st_time_mode.act == TIME_MODE_INIT) ? true:false;
	
}

//---------------------------------------------------------------------------------