//************************************************** // SDカードを使えるようにします: System.useSD // System.useSD() //戻り値 // 0:使用不可, 1:使用可能 //************************************************** mrb_value mrb_system_useSD(mrb_state *mrb, mrb_value self) { int ret = 0; #if BOARD == BOARD_GR || FIRMWARE == SDBT || FIRMWARE == SDWF || BOARD == BOARD_P05 || BOARD == BOARD_P06 ret = sdcard_Init(mrb); //SDカード関連メソッドの設定 #endif return mrb_fixnum_value( ret ); }
//************************************************** // ライブラリを定義します //************************************************** int mp3_Init(mrb_state *mrb,int pausePin, int stopPin) { PausePin = pausePin; StopPin = stopPin; //使用できるピンかどうかチェック if(PausePin == StopPin){ return 0; } if(!chkCanUsePin(PausePin) || !chkCanUsePin(StopPin)){ return 0; } //SDカードが利用可能か確かめます if(!sdcard_Init(mrb)){ return 0; } //インスタンスを作成する前には、強制gcを入れる mrb_full_gc(mrb); //インスタンスを生成します。 if(Wavmp3p == 0){ Wavmp3p = new WavMp3p(44100); } pinMode(PausePin, INPUT_PULLUP); pinMode(StopPin, INPUT_PULLUP); MsTimer2::set(100, cyclic_handler); struct RClass *mp3Module = mrb_define_module(mrb, MP3_CLASS); mrb_define_module_function(mrb, mp3Module, "play", mrb_mp3_play, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mp3Module, "led", mrb_mp3_led, MRB_ARGS_REQ(1)); return 1; }
int main() { sdcard_Init(); initVGA(); initAnonProfile(); brickmap = malloc(sizeof(BrickMap)); currentLevel->paddle = malloc(sizeof(Paddle)); currentLevel->buff=malloc(sizeof(Buff)); int i,j; for(i=0;i<maxBalls;i++) currentLevel->ball[i] = malloc(sizeof(Ball)); for(i=0;i<maxRows;i++) for(j=0;j<bricksPerRow;j++) currentLevel->bricks[i][j]=malloc(sizeof(Brick)); level=1; //pre load the root menu getMenu(¤tMenu,rootMenu, 1); //allocate memory for level farm //set the game to playing prevState=currentState=Playing; //look up the level from level farm and load it into currentLevel levelLookUp(brickmap,level); initLevel(*brickmap); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); runCountDown(); //count down from three initInterrupt(); //start the game (we dont need to right off the bat (probably shouldnt) int counter=0; //so were not doing direct IO reads on EVERY iteration (we could timer this buttttt no) while(1) { //input to state machine counter++; if(counter>22000) { counter=0; if(getMenuPB()) { while(getMenuPB() != 0); if(currentState == Playing) changeState(MenuShow); } } //flicker changes if(prevState != currentState) { if(currentState == Playing) { clearScreen(); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); runCountDown(); initInterrupt(); }else { stopInterrupt(); getMenu(¤tMenu,rootMenu, 1); clearScreen(); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); drawMenu(currentMenu); } prevState = currentState; } //state machine if(currentState == MenuShow) { menuLoop(); }else //while were playing we will have to check for other things (all balls gone etc.) { if(currentLevel->brickCount<=0) { printf("starting new level \n"); stopInterrupt(); level++; levelLookUp(brickmap,level); initLevel(*brickmap); prevState= currentState - 1; currentState = Playing; printf("finished starting new level \n"); } } } return 0; }