Beispiel #1
0
int main(void) {

    MCU_Clk_Init();
    Input_Init();
    Output_Init();
    LCD_Init();
    // Cau hinh timer xay ra ngat sau 1s
    Timer0A_Config(40000000);

    Write_Str("Hello World!", 0, 0);

    while (1) {
        if (CuaDong) {
            // Bat den
            door_is_close = true;
            GPIOPinWrite(GPIO_PORTB_BASE, LIGHT_PIN, LIGHT_PIN);
        } else {
            door_is_close = false;
            if (is_active) {
                // Neu dang nuong ma mo cua thi tat ngay lap tuc thiet bi nuong, tat timer va bat loa canh bao
                GPIOPinWrite(GPIO_PORTB_BASE, GRILL_PIN, GRILL_PIN);
                GPIOPinWrite(GPIO_PORTB_BASE, MICRO_PIN, MICRO_PIN);
                TimerDisable(TIMER0_BASE, TIMER_A);
                GPIOPinWrite(GPIO_PORTB_BASE, SPEAKER_PIN, 0);
            } else {
                // Neu da nuong xong va cua mo thi tat loa
                GPIOPinWrite(GPIO_PORTB_BASE, SPEAKER_PIN, 0);
            }

        }
    }
}
Beispiel #2
0
int main(int argc, char **argv)
#endif /* __APPLE__ */
{
	bool commit_dune_cfg = false;
#if defined(_WIN32)
	#if defined(__MINGW32__) && defined(__STRICT_ANSI__)
		int __cdecl __MINGW_NOTHROW _fileno (FILE*);
	#endif
	FILE *err = fopen("error.log", "w");
	FILE *out = fopen("output.log", "w");

	#if defined(_MSC_VER)
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	#endif

	if (err != NULL) _dup2(_fileno(err), _fileno(stderr));
	if (out != NULL) _dup2(_fileno(out), _fileno(stdout));
	FreeConsole();
#endif
	CrashLog_Init();

	VARIABLE_NOT_USED(argc);
	VARIABLE_NOT_USED(argv);

	if (!File_Init()) {
		Error("Cannot initialise files. Does %s directory exist ?\n", DATA_DIR);
		exit(1);
	}

	/* Loading / writing config from/to dune.cfg */
	if (!Config_Read("dune.cfg", &g_config)) {
		Config_Default(&g_config);
		commit_dune_cfg = true;
	}
	if (commit_dune_cfg && !Config_Write("dune.cfg", &g_config)) {
		Error("Error writing to dune.cfg file.\n");
		exit(1);
	}

	Input_Init();

	Drivers_All_Init();

	if (!Unknown_25C4_000E()) exit(1);

	g_var_7097 = 0;

	GameLoop_Main();

	printf("%s\n", String_Get_ByIndex(STR_THANK_YOU_FOR_PLAYING_DUNE_II));

	PrepareEnd();
	exit(0);
}
Beispiel #3
0
int main(int argc, char** argv)
{
	UNUSED(argc);
	UNUSED(argv);

	FileHash_Init();
	Mouse_Init();

	if (A5_InitOptions() == false)
		exit(1);

	char filename[1024];

	snprintf(filename, sizeof(filename), "%s/error.log", g_dune_data_dir);
	FILE* err = fopen(filename, "w");

	snprintf(filename, sizeof(filename), "%s/output.log", g_dune_data_dir);
	FILE* out = fopen(filename, "w");

	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	if (err != NULL)
		_dup2(_fileno(err), _fileno(stderr));
	if (out != NULL)
		_dup2(_fileno(out), _fileno(stdout));
	FreeConsole();

	if (!Unknown_25C4_000E())
		exit(1);

	if (A5_Init() == false)
		exit(1);

	Scenario_InitTables();
	Input_Init();
	Audio_LoadSampleSet(SAMPLESET_INVALID);
	String_Init();
	Sprites_Init();
	Sprites_LoadTiles();
	VideoA5_InitSprites();
	GameLoop_TweakWidgetDimensions();
	Audio_PlayVoice(VOICE_STOP);
	GameLoop_GameIntroAnimationMenu();

	printf("%s\n", String_Get_ByIndex(STR_THANK_YOU_FOR_PLAYING_DUNE_II));

	PrepareEnd();
	exit(0);
}
Beispiel #4
0
int main(int argc, char **argv)
#endif /* __APPLE__ */
{
	bool commit_dune_cfg = false;
	VideoScaleFilter scale_filter = FILTER_NEAREST_NEIGHBOR;
	int scaling_factor = 2;
	char filter_text[64];
#if defined(_WIN32)
	#if defined(__MINGW32__) && defined(__STRICT_ANSI__)
		int __cdecl __MINGW_NOTHROW _fileno (FILE*);
	#endif
	FILE *err = fopen("error.log", "w");
	FILE *out = fopen("output.log", "w");

	#if defined(_MSC_VER)
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	#endif

	if (err != NULL) _dup2(_fileno(err), _fileno(stderr));
	if (out != NULL) _dup2(_fileno(out), _fileno(stdout));
	FreeConsole();
#endif
#ifdef TOS
	(void)Cconws(window_caption);
	(void)Cconws("\r\nrevision:   ");
	(void)Cconws(g_opendune_revision);
	(void)Cconws("\r\nbuild date: ");
	(void)Cconws(g_opendune_build_date);
	(void)Cconws("\r\n");
	/* open log files and set buffering mode */
	g_errlog = fopen("error.log", "w");
	if(g_errlog != NULL) setvbuf(g_errlog, NULL, _IONBF, 0);
#ifdef _DEBUG
	g_outlog = fopen("output.log", "w");
	if(g_outlog != NULL) setvbuf(g_outlog, NULL, _IOLBF, 0);
#endif
	if(atexit(exit_handler) != 0) {
		Error("atexit() failed\n");
	}
#endif
	CrashLog_Init();

	VARIABLE_NOT_USED(argc);
	VARIABLE_NOT_USED(argv);

	/* Load opendune.ini file */
	Load_IniFile();

	if (!File_Init()) {
		exit(1);
	}

	/* Loading config from dune.cfg */
	if (!Config_Read("dune.cfg", &g_config)) {
		Config_Default(&g_config);
		commit_dune_cfg = true;
	}
	/* reading config from opendune.ini which prevail over dune.cfg */
	SetLanguage_From_IniFile(&g_config);

	/* Writing config to dune.cfg */
	if (commit_dune_cfg && !Config_Write("dune.cfg", &g_config)) {
		Error("Error writing to dune.cfg file.\n");
		exit(1);
	}

	Input_Init();

	Drivers_All_Init();

	scaling_factor = IniFile_GetInteger("scalefactor", 2);
	if (IniFile_GetString("scalefilter", NULL, filter_text, sizeof(filter_text)) != NULL) {
		if (strcasecmp(filter_text, "nearest") == 0) {
			scale_filter = FILTER_NEAREST_NEIGHBOR;
		} else if (strcasecmp(filter_text, "scale2x") == 0) {
			scale_filter = FILTER_SCALE2X;
		} else if (strcasecmp(filter_text, "hqx") == 0) {
			scale_filter = FILTER_HQX;
		} else {
			Error("unrecognized scalefilter value '%s'\n", filter_text);
		}
	}

	if (!OpenDune_Init(scaling_factor, scale_filter)) exit(1);

	g_mouseDisabled = 0;

	GameLoop_Main();

	printf("%s\n", String_Get_ByIndex(STR_THANK_YOU_FOR_PLAYING_DUNE_II));

	PrepareEnd();
	Free_IniFile();
	exit(0);
}
void GameLoop( void )
{
    GS_Initialize( &GS_level_tetris );
    WinMgr_Init( 400, 720 );    // set window size
    Graphics_Init( 400, 720 );
    FrameRate_Init( 30 );    // Set max frame rate
    Input_Init();

    while( GS_current != GS_QUIT )
    {
        // reset the system modules
        //System::Reset();

        // If not restarting, load the gamestate
        if( GS_current != GS_RESTART )
        {
            //GameStateManager::Update();
            GS_current->Load();
        }
        else
            GS_next = GS_current = GS_previous;

        // Initialize the gamestate
        GS_current->Init();
        FrameRate_Reset(); // reset the clock

        while( GS_current == GS_next )
        {
            Graphics_BeginFrame();
            Input_Update();
            GS_current->Update();
            GS_current->Draw();
            Graphics_EndFrame();

            FrameRate_Wait();
            WinMgr_Swap();

            // handle signals from window
            switch( WinMgr_Update() )
            {
            case WM_NONE:
                break;

            case WM_CLOSE:
                GS_next = GS_QUIT;

            case WM_RESIZE:
                // TODO: update graphics viewport
                break;

            default:
                // error
                break;
            }

            //System::Update();
        }

        GS_current->Free();

        if(GS_next != GS_RESTART)
            GS_current->Unload();

        GS_previous = GS_current;
        GS_current = GS_next;
    }

    Input_Exit();
    FrameRate_Exit();
    Graphics_Exit();
    WinMgr_Exit();
}
Beispiel #6
0
int main(void) {
    int addScore, position, pauseSel;

    // Initializations
    PLL_Init();  			// Clock set at 80 MHz
    LCD_Init();
    Board_Init();
    Input_Init();
    DAC_Init();
    Random_Init(NVIC_ST_CURRENT_R);
    Timer2_Init(80000000); 	// time interrupt
    Timer1_Init(2000);		// sound interrupt
    EnableInterrupts();
    generateRandomTile();
    drawAllTiles();
    writeScore(0);
    writeHighscore(0);
    writeTime(0);
    displayHighestTile();

    while(1) {

        // draw arrow if ready
        if (arrowReady == 1) {
            // acknowledge flag
            arrowReady = 0;
            // draw arrow
            drawArrow();
        }

        // write time if ready
        if (timeReady == 1) {
            // acknowledge flag
            timeReady = 0;
            // write time
            writeTime(elapsedTime);
        }

        // Play mode and button1 is pushed
        if(Button1 && !pauseMode && !gameOver) {
            // Play sound
            playSound = 1;
            // shift and merge tiles towards arrow
            position = getSliderPosition();
            if (position == 1) {
                shiftLeft();
                addScore = mergeLeft();
                shiftLeft();
            }
            else if (position == 2) {
                shiftUp();
                addScore = mergeUp();
                shiftUp();
            }
            else if (position == 3) {
                shiftRight();
                addScore = mergeRight();
                shiftRight();
            }
            else {
                shiftDown();
                addScore = mergeDown();
                shiftDown();
            }

            eraseBoard();
            drawAllTiles();

            // update score
            score += addScore;
            addScore = 0;
            writeScore(score);
            displayHighestTile();

            // delay before adding new tile
            delay(200);

            // create new tile
            if (countEmptyTiles() != 0) {
                generateRandomTile();
            }
            drawAllTiles();

            // update highest tile image
            displayHighestTile();

            // check if game over
            if (checkGameOver() == 1) {
                gameOver = 1;
            }

            // unset flag
            Button1 = 0;
        }

        // button 2 is pause
        else if (Button2 && !gameOver && !pauseMode) {
            pauseMode = 1;
            pauseSel = 0;

            // disable arrow and timer
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);

            // draw pause mode screen
            drawPauseMode();

            // acknowledge button
            Button2 = 0;

            // wait until button is pushed
            while (pauseMode) {

                // Button 1 selects current pause selection button
                if (Button1) {

                    // acknowledge button
                    Button1 = 0;
                    Button2 = 0;
                    pauseMode = 0;

                    // if pause selection = "continue" (pauseSel = 0), continue with game
                    if (pauseSel == 0) {

                        // redraw screen
                        eraseBoard();
                        drawAllTiles();

                        // enable gameplay
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }

                    // if pause selection = "restart" (pauseSel = 0), end game
                    else if (pauseSel == 1) {
                        if (score > highscore) {
                            writeHighscore(score);
                        }
                        score = 0;
                        eraseScore();
                        writeScore(0);
                        clearBoard();
                        eraseBoard();
                        pauseMode = 0;
                        generateRandomTile();
                        drawAllTiles();
                        elapsedTime = 0;
                        eraseTime();
                        writeTime(0);
                        displayHighestTile();
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }
                }

                // Button 2 changes pause selection
                else if (Button2) {
                    Button2 = 0;
                    if (pauseSel == 0) {
                        pauseSel = 1;
                        LCD_DrawRect(144,112,58,16,BLACK);
                        LCD_DrawRect(222,112,51,16,WHITE);
                    }
                    else if (pauseSel == 1) {
                        pauseSel = 0;
                        LCD_DrawRect(222,112,51,16,BLACK);
                        LCD_DrawRect(144,112,58,16,WHITE);
                    }
                }
            }
        }

        // game over
        if (gameOver == 1) {
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(156,38,100,20,BLACK);
            LCD_SetTextColor(255,255,240);
            LCD_Goto(30,5);
            printf("GAME OVER");
            while (Button1 == 0 && Button2 == 0) {}
            Button1 = 0;
            Button2 = 0;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);
            drawGameOver(score, elapsedTime);
            if (score > highscore) {
                writeHighscore(score);
                gameOverHighscore(score);
            }
            // wait til button is pushed
            while (Button1 == 0 && Button2 == 0) {}
            // acknowledge buttons
            Button1 = 0;
            Button2 = 0;
            // start new game
            score = 0;
            eraseScore();
            writeScore(0);
            clearBoard();
            eraseBoard();
            pauseMode = 0;
            generateRandomTile();
            drawAllTiles();
            elapsedTime = 0;
            eraseTime();
            writeTime(0);
            displayHighestTile();
            NVIC_ST_CTRL_R = 0x07;
            TIMER2_CTL_R = 0x00000001;

            // finish game over mode
            gameOver = 0;
        }
    }
}