ディスプレイモジュールがゲーム盤面として NDS 上画面にあり、
コントロールモジュールがコンパネとして NDS 下画面にあるものと想定してます。
コントロールとは言ってもボタン入力は担わせてません。
main.c
/*--------------------------------------------------------------------------------- ctrl module test version 0.01 Jan 18, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <stdio.h> #include <nds/ndstypes.h> #include <nds/interrupts.h> #include <nds/arm9/input.h> #include <nds/arm9/console.h> #include "Ctrl.h" //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- consoleDemoInit(); printf("\x01b[0;0Hctrl module test\n\nversion 0.01\nJan 18, 2010\n\nBy. REGEKATSU\n\n\n"); Ctrl_Clear(); while(1) { swiWaitForVBlank(); scanKeys(); if(keysDown() & KEY_LEFT){ Ctrl_SetLED(CTRL_GOO); }else if(keysDown() & KEY_UP){ Ctrl_SetLED(CTRL_CHOKI); }else if(keysDown() & KEY_RIGHT){ Ctrl_SetLED(CTRL_PAR); }else if(keysDown() & KEY_A){ Ctrl_SetLED(CTRL_START); }else if(keysDown() & KEY_B){ Ctrl_SetLED(CTRL_RETURN); }else if(keysDown() & KEY_START){ Ctrl_SetLED(0); }else if(keysDown() & KEY_SELECT){ Ctrl_SetLED(CTRL_GOO | CTRL_CHOKI | CTRL_PAR); } } } //---------------------------------------------------------------------------------
Ctrl.h
/*--------------------------------------------------------------------------------- ctrl module header version 0.01 Jan 18, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _CTRL_H_ #define _CTRL_H_ #include <nds/ndstypes.h> typedef enum{ CTRL_GOO = BIT(0), CTRL_CHOKI = BIT(1), CTRL_PAR = BIT(2), CTRL_START = BIT(3), CTRL_RETURN = BIT(4) }CTRL_BITS; #ifdef __cplusplus extern "C" { #endif void Ctrl_Clear(void); void Ctrl_SetLED(CTRL_BITS led); #ifdef __cplusplus } #endif #endif //_CTRL_H_
Ctrl.c
/*--------------------------------------------------------------------------------- ctrl module routine version 0.01 Jan 18, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <stdio.h> #include <string.h> #include "Ctrl.h" typedef struct{ u8 led; }CtrlStatus; static CtrlStatus st_ctrl; #define IS_VAL(x) ((x)?true:false) void ctrl_DrawLED(void); //--------------------------------------------------------------------------------- void Ctrl_Clear(void){ //--------------------------------------------------------------------------------- memset(&st_ctrl, 0, sizeof(st_ctrl)); ctrl_DrawLED(); } //--------------------------------------------------------------------------------- void Ctrl_SetLED(CTRL_BITS led){ //--------------------------------------------------------------------------------- st_ctrl.led = led & 0x1f; ctrl_DrawLED(); } //--------------------------------------------------------------------------------- void ctrl_DrawLED(void){ //--------------------------------------------------------------------------------- printf("\x01b[9;0H STA GOO CHO PAR RET\n"); printf(" %03d", IS_VAL( st_ctrl.led & CTRL_START )); printf(" %03d", IS_VAL( st_ctrl.led & CTRL_GOO )); printf(" %03d", IS_VAL( st_ctrl.led & CTRL_CHOKI )); printf(" %03d", IS_VAL( st_ctrl.led & CTRL_PAR )); printf(" %03d", IS_VAL( st_ctrl.led & CTRL_RETURN )); } //---------------------------------------------------------------------------------