diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2017-08-14 14:29:04 +0200 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2017-08-14 14:29:04 +0200 |
| commit | db8bc5f9e386c76531dfe679df022dd05d3dd27a (patch) | |
| tree | 03ddd1ab050c79fa56e51a1f7c3d4c15bd1685b6 | |
| parent | f97f48ca7cefd3380edc9bdaaebf17c16c5c871b (diff) | |
+ Documentation about sound sources.
* Sine-like effect used for runways now moved to SystemCalculateSine().
* Bugfix: ptrPlayer->FlightDataPage is now decreased if there aren't enough active aircraft.
* On main menu, 2 players option is now disabled if pad 2 is disconnected.
* More work on FPS measurement (not working yet).
* Number of used SPU voices is now returned on SfxUploadSound().
| -rw-r--r-- | Sounds/SOUND_SOURCES | 11 | ||||
| -rw-r--r-- | Source/Aircraft.c | 43 | ||||
| -rw-r--r-- | Source/Camera.c | 13 | ||||
| -rw-r--r-- | Source/Game.c | 182 | ||||
| -rw-r--r-- | Source/Game.h | 1 | ||||
| -rw-r--r-- | Source/GameGui.c | 18 | ||||
| -rw-r--r-- | Source/Gfx.c | 16 | ||||
| -rw-r--r-- | Source/LoadMenu.c | 24 | ||||
| -rw-r--r-- | Source/Menu.c | 37 | ||||
| -rw-r--r-- | Source/Sfx.c | 3 | ||||
| -rw-r--r-- | Source/System.c | 114 | ||||
| -rw-r--r-- | Source/System.h | 10 |
12 files changed, 394 insertions, 78 deletions
diff --git a/Sounds/SOUND_SOURCES b/Sounds/SOUND_SOURCES new file mode 100644 index 0000000..da49afd --- /dev/null +++ b/Sounds/SOUND_SOURCES @@ -0,0 +1,11 @@ +Bell sound obtained from: +http://freesound.org/people/InspectorJ/sounds/339812/ + +Radio chatter obtained from: +http://freesound.org/people/digifishmusic/sounds/55022/ + +Tray close sound obtained from: +http://freesound.org/people/Hard3eat/sounds/351780/ + +CD sound obtained from: +http://freesound.org/people/cmorris035/sounds/207276/ diff --git a/Source/Aircraft.c b/Source/Aircraft.c index 9cfba20..0347edd 100644 --- a/Source/Aircraft.c +++ b/Source/Aircraft.c @@ -355,9 +355,46 @@ void AircraftRender(TYPE_PLAYER* ptrPlayer, uint8_t aircraftIdx) CameraApplyCoordinatesToSprite(ptrPlayer, &AircraftSpr);
- AircraftSpr.r = NORMAL_LUMINANCE;
- AircraftSpr.g = NORMAL_LUMINANCE;
- AircraftSpr.b = NORMAL_LUMINANCE;
+ if( (ptrPlayer->FlightDataSelectedAircraft == aircraftIdx)
+ &&
+ (ptrPlayer->ShowAircraftData == true) )
+ {
+ static uint8_t aircraft_sine;
+ static bool aircraft_sine_decrease;
+
+ if(aircraft_sine_decrease == false)
+ {
+ if(aircraft_sine < 240)
+ {
+ aircraft_sine += 24;
+ }
+ else
+ {
+ aircraft_sine_decrease = true;
+ }
+ }
+ else
+ {
+ if(aircraft_sine > 24)
+ {
+ aircraft_sine -= 24;
+ }
+ else
+ {
+ aircraft_sine_decrease = false;
+ }
+ }
+
+ AircraftSpr.r = NORMAL_LUMINANCE >> 2;
+ AircraftSpr.g = NORMAL_LUMINANCE >> 2;
+ AircraftSpr.b = aircraft_sine;
+ }
+ else
+ {
+ AircraftSpr.r = NORMAL_LUMINANCE;
+ AircraftSpr.g = NORMAL_LUMINANCE;
+ AircraftSpr.b = NORMAL_LUMINANCE;
+ }
GfxSortSprite(&AircraftSpr);
}
diff --git a/Source/Camera.c b/Source/Camera.c index d826f54..9f4e115 100644 --- a/Source/Camera.c +++ b/Source/Camera.c @@ -18,6 +18,13 @@ #define CAMERA_INITIAL_X_OFFSET_2PLAYER (X_SCREEN_RESOLUTION >> 2) /* ************************************* + * Local Variables + * *************************************/ + +static int32_t Camera_Max_X_Offset; +static int32_t Camera_Max_Y_Offset; + +/* ************************************* * Local Prototypes * *************************************/ @@ -32,6 +39,9 @@ void CameraInit(TYPE_PLAYER* ptrPlayer) ptrPlayer->Camera.X_Speed = 0; ptrPlayer->Camera.Y_Speed = 0; ptrPlayer->Camera.Speed_Timer = SPEED_CALCULATION_TIME; + + Camera_Max_X_Offset = GameGetLevelColumns() << TILE_SIZE_BIT_SHIFT; + Camera_Max_Y_Offset = GameGetLevelColumns() * TILE_SIZE_H; } void CameraApplyCoordinatesToSprite(TYPE_PLAYER* ptrPlayer, GsSprite * spr) @@ -149,6 +159,9 @@ void CameraHandler(TYPE_PLAYER* ptrPlayer) ptrPlayer->Camera.X_Offset += ptrPlayer->Camera.X_Speed; ptrPlayer->Camera.Y_Offset += ptrPlayer->Camera.Y_Speed; + + //DEBUG_PRINT_VAR(ptrPlayer->Camera.X_Offset); + //DEBUG_PRINT_VAR(ptrPlayer->Camera.Y_Offset); } bool CameraSpecialConditions(TYPE_PLAYER* ptrPlayer) diff --git a/Source/Game.c b/Source/Game.c index 74f4706..33bc903 100644 --- a/Source/Game.c +++ b/Source/Game.c @@ -203,7 +203,6 @@ static uint16_t GameRwy[GAME_MAX_RUNWAYS]; static TYPE_FLIGHT_DATA FlightData; static uint16_t GameUsedRwy[GAME_MAX_RUNWAYS]; static uint16_t GameSelectedTile; -static bool firstLevelRender; // Used to avoid reentrance issues on GameRenderLevel() static TYPE_TIMER* GameSpawnMinTime; static bool spawnMinTimeFlag; static bool GameAircraftCreatedFlag; @@ -213,7 +212,7 @@ static TYPE_BUILDING_DATA GameBuildingData[MAX_BUILDING_ID]; static uint8_t GameAircraftTilemap[GAME_MAX_MAP_SIZE][GAME_MAX_AIRCRAFT_PER_TILE]; // Instances for player-specific data -TYPE_PLAYER PlayerData[MAX_PLAYERS]; +static TYPE_PLAYER PlayerData[MAX_PLAYERS]; static char* GameFileList[] = { "cdrom:\\DATA\\SPRITES\\TILESET1.TIM;1" , "cdrom:\\DATA\\SPRITES\\GAMEPLN.TIM;1" , @@ -655,6 +654,7 @@ void GameBuildingsInit(void) void GameEmergencyMode(void) { uint8_t i; + uint8_t disconnected_players = 0x00; bool (*PadXConnected[MAX_PLAYERS])(void) = { [PLAYER_ONE] = &PadOneConnected, [PLAYER_TWO] = &PadTwoConnected }; @@ -670,9 +670,18 @@ void GameEmergencyMode(void) ERROR_RECT_G = 32, ERROR_RECT_B = NORMAL_LUMINANCE }; + + enum + { + PAD_DISCONNECTED_TEXT_X = 48, + PAD_DISCONNECTED_TEXT_Y = 48, + PAD_DISCONNECTED_TEXT_Y_OFFSET_BITSHIFT = 5 + }; - while(SystemGetEmergencyMode() == true) + do { + bool enabled = false; + GsRectangle errorRct = {.x = ERROR_RECT_X, .w = ERROR_RECT_W, .y = ERROR_RECT_Y, @@ -681,12 +690,27 @@ void GameEmergencyMode(void) .g = ERROR_RECT_G, .b = ERROR_RECT_B }; - // Pad one has been disconnected during gameplay - // Show an error screen until it is disconnected again. - - GsSortCls(0,0,0); - - GsSortRectangle(&errorRct); + if(SystemGetEmergencyMode() == true) + { + // One of the pads has been disconnected during gameplay + // Show an error screen until it is disconnected again. + + GsSortCls(0,0,0); + GsSortRectangle(&errorRct); + + for(i = 0; i < MAX_PLAYERS; i++) + { + if(disconnected_players & (1<<i) ) + { + FontPrintText( &SmallFont, + PAD_DISCONNECTED_TEXT_X, + PAD_DISCONNECTED_TEXT_Y + (i << PAD_DISCONNECTED_TEXT_Y_OFFSET_BITSHIFT), + "Pad %s disconnected", i? "right" : "left" ); + } + } + + GfxDrawScene_Slow(); + } for(i = 0; i < MAX_PLAYERS; i++) { @@ -696,14 +720,19 @@ void GameEmergencyMode(void) { if(PadXConnected[i]() == false) { - FontPrintText(&SmallFont, 48, 48 + (i << 5), "Pad %d disconnected", i); - SystemSetEmergencyMode(true); + enabled = true; + disconnected_players |= 1<<i; + } + else + { + disconnected_players &= ~(1<<i); } } } - GfxDrawScene_Slow(); - } + SystemSetEmergencyMode(enabled); + + }while(SystemGetEmergencyMode() == true); } /* *************************************************************************************** @@ -837,6 +866,13 @@ void GamePlayerHandler(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData) CameraMoveToIsoPos(ptrPlayer, IsoPos); } + if(System1SecondTick() == true) + { + dprintf("ptrPlayer = 0x%08X\n", ptrPlayer); + DEBUG_PRINT_VAR(ptrPlayer->ActiveAircraft); + DEBUG_PRINT_VAR(ptrPlayer->FlightDataPage); + } + GameActiveAircraftList(ptrPlayer, ptrFlightData); GameStateUnboarding(ptrPlayer, ptrFlightData); GameStateLockTarget(ptrPlayer, ptrFlightData); @@ -946,9 +982,11 @@ void GameGraphics(void) { int i; bool split_screen = false; + + SystemAcknowledgeFrame(); while( (SystemRefreshNeeded() == false) || (GfxIsGPUBusy() == true) ); - + if(TwoPlayersActive == true) { split_screen = true; @@ -960,14 +998,16 @@ void GameGraphics(void) GfxIncreaseGlobalLuminance(1); } - firstLevelRender = true; + GsSortCls(0,0,GfxGetGlobalLuminance() >> 1); + + while(GsIsDrawing()); for(i = 0; i < MAX_PLAYERS ; i++) { TYPE_PLAYER* ptrPlayer = &PlayerData[i]; if(ptrPlayer->Active == true) - { + { if(split_screen == true) { GfxSetSplitScreen(i); @@ -976,8 +1016,6 @@ void GameGraphics(void) // Draw half split screen for each player // only if 2-player mode is active. Else, render // the whole screen as usual. - - GsSortCls(0,0,GfxGetGlobalLuminance() >> 1); // Ground tiles must be rendered first. @@ -1415,9 +1453,7 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer) bool used_rwy = SystemContains_u16(ptrPlayer->RwyArray[0], GameUsedRwy, GAME_MAX_RUNWAYS); uint8_t aux_id; GsSprite * ptrTileset; - const uint8_t rwy_sine_step = 24; - static unsigned char rwy_sine = rwy_sine_step; - static bool rwy_sine_decrease = false; + unsigned char rwy_sine = SystemGetSineValue(); TYPE_ISOMETRIC_POS tileIsoPos; TYPE_CARTESIAN_POS tileCartPos; @@ -1437,36 +1473,6 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer) Serial_printf("\n");*/ } - - if(firstLevelRender == true) - { - // Avoid re-entrance. - - firstLevelRender = false; - - if(rwy_sine_decrease == false) - { - if(rwy_sine < 240) - { - rwy_sine += rwy_sine_step; - } - else - { - rwy_sine_decrease = true; - } - } - else - { - if(rwy_sine > rwy_sine_step) - { - rwy_sine -= rwy_sine_step; - } - else - { - rwy_sine_decrease = false; - } - } - } for(i = 0 ; i < GameLevelSize; i++) { @@ -3191,6 +3197,21 @@ void GameDrawMouse(TYPE_PLAYER* ptrPlayer) } } +/* ******************************************************************************** + * + * @name: FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx) + * + * @author: Xavier Del Campo + * + * @param: + * uint8_t FlightDataIdx: + * Index from FlightData. + * + * @return: + * Returns .State variable given offset from FlightData. + * + * ********************************************************************************/ + FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx) { if(FlightDataIdx >= FlightData.nAircraft) @@ -3201,13 +3222,43 @@ FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx) return FlightData.State[FlightDataIdx]; } +/* ******************************************************************************** + * + * @name: uint32_t GameGetScore(void) + * + * @author: Xavier Del Campo + * + * @return: + * Returns game score to other modules. + * + * ********************************************************************************/ + uint32_t GameGetScore(void) { return GameScore; } +/* ******************************************************************************************* + * + * @name: void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData) + * + * @author: Xavier Del Campo + * + * @param: + * TYPE_PLAYER* ptrPlayer: + * Pointer to a player structure + * + * TYPE_FLIGHT_DATA* ptrFlightData: + * In the end, pointer to FlightData data table, which contains + * information about all available flights. + * + * @brief: + * Handler for StateUnboarding. + * + * *******************************************************************************************/ + void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData) -{ +{ if(ptrPlayer->Unboarding == true) { if(ptrPlayer->PadKeySinglePress_Callback(PAD_CIRCLE) == true) @@ -3254,6 +3305,25 @@ void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData } } +/* ******************************************************************************************* + * + * @name: void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData) + * + * @author: Xavier Del Campo + * + * @param: + * TYPE_PLAYER* ptrPlayer: + * Pointer to a player structure + * + * @brief: + * Modifies ptrPlayer->UnboardingSequence creating a random sequence of numbers + * using SystemRand(). + * + * @todo: + * Maximum number of sequence keys should be adjusted according to difficulty. + * + * *******************************************************************************************/ + void GameGenerateUnboardingSequence(TYPE_PLAYER* ptrPlayer) { uint8_t i; @@ -3292,22 +3362,22 @@ void GameCreateTakeoffWaypoints(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli switch(aircraftDir) { case AIRCRAFT_DIR_EAST: - Serial_printf("EAST\n"); + //Serial_printf("EAST\n"); rwyStep = 1; break; case AIRCRAFT_DIR_WEST: - Serial_printf("WEST\n"); + //Serial_printf("WEST\n"); rwyStep = -1; break; case AIRCRAFT_DIR_NORTH: - Serial_printf("NORTH\n"); + //Serial_printf("NORTH\n"); rwyStep = -GameLevelColumns; break; case AIRCRAFT_DIR_SOUTH: - Serial_printf("SOUTH\n"); + //Serial_printf("SOUTH\n"); rwyStep = GameLevelColumns; break; diff --git a/Source/Game.h b/Source/Game.h index 69e6bb4..5683cda 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -25,7 +25,6 @@ * *************************************/ extern bool GameStartupFlag; -extern TYPE_PLAYER PlayerData[]; /* ************************************* * Global prototypes diff --git a/Source/GameGui.c b/Source/GameGui.c index e501827..237ef0e 100644 --- a/Source/GameGui.c +++ b/Source/GameGui.c @@ -335,11 +335,19 @@ void GameGuiActiveAircraftPage(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlig ptrPlayer->SelectedAircraft--;
}
}
-
- while(ptrPlayer->ActiveAircraft < (uint8_t)(GAME_GUI_AIRCRAFT_DATA_MAX_PAGE * ptrPlayer->FlightDataPage) )
- {
- ptrPlayer->FlightDataPage--;
- }
+
+ if(ptrPlayer->ActiveAircraft != 0)
+ {
+ while(ptrPlayer->ActiveAircraft <= (uint8_t)(GAME_GUI_AIRCRAFT_DATA_MAX_PAGE * ptrPlayer->FlightDataPage) )
+ {
+ ptrPlayer->FlightDataPage--;
+ }
+ }
+
+ while(ptrPlayer->SelectedAircraft > (uint8_t)(GAME_GUI_AIRCRAFT_DATA_MAX_PAGE * (ptrPlayer->FlightDataPage + 1)) )
+ {
+ ptrPlayer->FlightDataPage++;
+ }
if(ptrPlayer->ShowAircraftData == true)
{
diff --git a/Source/Gfx.c b/Source/Gfx.c index da1b378..85b36de 100644 --- a/Source/Gfx.c +++ b/Source/Gfx.c @@ -17,8 +17,8 @@ #define UPLOAD_IMAGE_FLAG 1 #define MAX_LUMINANCE 0xFF #define ROTATE_BIT_SHIFT 12 -#define GPUSTAT (*(unsigned int*)0x1F801814) -#define D2_CHCR (*(unsigned int*)0x1F8010A8) +#define GPUSTAT (*(volatile unsigned int*)0x1F801814) +#define D2_CHCR (*(volatile unsigned int*)0x1F8010A8) /* ************************************* * Structs and enums @@ -179,8 +179,18 @@ void GfxSetPrimitiveList(void) void GfxDrawScene_Fast(void) { + enum + { + FPS_INFO_X = 16, + FPS_INFO_Y = 16 + }; + SystemDevMenu(); + FontSetFlags(&SmallFont, FONT_NOFLAGS); + + FontPrintText(&SmallFont, FPS_INFO_X, FPS_INFO_Y, "%d/%d", SystemGetFPS(), REFRESH_FREQUENCY); + if(System1SecondTick() == true) { one_second_show = one_second_show? false:true; @@ -302,7 +312,7 @@ void GfxSortSprite(GsSprite * spr) spr->x = aux_x; } else - { + { GsSortSprite(spr); } diff --git a/Source/LoadMenu.c b/Source/LoadMenu.c index eb7735f..d7ea80a 100644 --- a/Source/LoadMenu.c +++ b/Source/LoadMenu.c @@ -261,11 +261,29 @@ void ISR_LoadMenuVBlank(void) uint8_t i; SystemIncreaseGlobalTimer(); + + if(SystemIsBusy() == true) + { + dprintf("SystemIsBusy...\n"); + return; + } + + if((GfxIsGPUBusy() == true)) + { + dprintf("(GfxIsGPUBusy() == true)\n"); + return; + } + + if(SerialIsBusy() == true) + { + dprintf("Serialisbusy\n"); + return; + } - if( (SystemIsBusy() == true) || (GfxIsGPUBusy() == true) || (SerialIsBusy() == true) ) + /*if( (SystemIsBusy() == true) || (GfxIsGPUBusy() == true) || (SerialIsBusy() == true) ) { return; - } + }*/ if(startup_flag == true) { @@ -456,8 +474,6 @@ void LoadMenuLoadFileList( char* fileList[], void* dest[], for(fileLoadedCount = 0; fileLoadedCount < szFileList ; fileLoadedCount++) { - DEBUG_PRINT_VAR(fileLoadedCount); - strCurrentFile = fileList[fileLoadedCount]; if(strCurrentFile == NULL) diff --git a/Source/Menu.c b/Source/Menu.c index a2350da..8d5141a 100644 --- a/Source/Menu.c +++ b/Source/Menu.c @@ -39,6 +39,7 @@ enum { MAIN_MENU_PLAY_OPTIONS_LEVEL_BUTTONS = 2, MAIN_MENU_ONE_TWO_PLAYERS_LEVEL_BUTTONS = 2, + MAIN_MENU_ONE_TWO_PLAYERS_LEVEL_BUTTONS_PAD_TWO_DISCONNECTED = 1, MAIN_MENU_OPTIONS_LEVEL_BUTTONS = 1 }; @@ -398,19 +399,33 @@ void MainMenuButtonHandler(void) break; case ONE_TWO_PLAYERS_LEVEL: - max_buttons = MAIN_MENU_ONE_TWO_PLAYERS_LEVEL_BUTTONS; + + if( (btn_selected == TWO_PLAYER_BUTTON_INDEX) + && + (PadTwoConnected() == false) ) + { + max_buttons = MAIN_MENU_ONE_TWO_PLAYERS_LEVEL_BUTTONS_PAD_TWO_DISCONNECTED; + } + else + { + max_buttons = MAIN_MENU_ONE_TWO_PLAYERS_LEVEL_BUTTONS; + } + if(PadOneKeySinglePress(PAD_TRIANGLE) == true) { menuLevel = PLAY_OPTIONS_LEVEL; MainMenuMinimumBtn = PLAY_BUTTON_INDEX; btn_selected = PLAY_BUTTON_INDEX; } + break; default: max_buttons = 0; break; } + + //DEBUG_PRINT_VAR(btn_selected); MainMenuBtn[previous_btn_selected].was_selected = MainMenuBtn[previous_btn_selected].selected; MainMenuBtn[btn_selected].was_selected = MainMenuBtn[btn_selected].selected; @@ -428,7 +443,7 @@ void MainMenuButtonHandler(void) { MainMenuBtn[btn_selected].selected = false; previous_btn_selected = btn_selected; - btn_selected++; + btn_selected++; SfxPlaySound(&BellSnd); } @@ -447,10 +462,11 @@ void MainMenuButtonHandler(void) { if(menuLevel == ONE_TWO_PLAYERS_LEVEL) { - MainMenuBtn[btn_selected].f(); - // Once gameplay has finished, turn back to first level - MainMenuRestoreInitValues(); - btn_selected = PLAY_BUTTON_INDEX; + // Start gameplay! + MainMenuBtn[btn_selected].f(); + // Once gameplay has finished, turn back to first level + MainMenuRestoreInitValues(); + btn_selected = PLAY_BUTTON_INDEX; } else { @@ -536,6 +552,15 @@ void MainMenuDrawButton(TYPE_MMBtn * btn) MenuSpr.y = MAIN_MENU_TWO_PLAYER_BUTTON_Y - MainMenuBtnAni[btn->timer]; MenuSpr.u += btn->offset_u; MenuSpr.v += btn->offset_v; + + // Exception: turn option dimmer if second player pad isn't connected + + if(PadTwoConnected() == false) + { + MenuSpr.r = NORMAL_LUMINANCE >> 1; + MenuSpr.g = NORMAL_LUMINANCE >> 1; + MenuSpr.b = NORMAL_LUMINANCE >> 1; + } GsSortSprite(&MenuSpr); break; diff --git a/Source/Sfx.c b/Source/Sfx.c index b6b46c6..c0033d0 100644 --- a/Source/Sfx.c +++ b/Source/Sfx.c @@ -47,7 +47,10 @@ bool SfxUploadSound(char* file_path, SsVag * vag) SsUploadVag(vag); vag->cur_voice = voiceIndex; + voiceIndex++; + + Serial_printf("SPU voices used = %d\n", voiceIndex); } else { diff --git a/Source/System.c b/Source/System.c index e3dbb86..7488028 100644 --- a/Source/System.c +++ b/Source/System.c @@ -41,6 +41,9 @@ static volatile uint64_t global_timer; static bool rand_seed; //Screen refresh flag (called by interrupt) static volatile bool refresh_needed; +// Frames per second measurement +static volatile uint8_t fps; +static volatile uint8_t temp_fps; //Timers static bool one_second_timer; static bool hundred_ms_timer; @@ -52,6 +55,8 @@ static volatile bool system_busy; // When true, it draws a rectangle on top of all primitives with // information for development purposes. static bool devmenu_flag; +// Used for sine-like effect. +static unsigned char sine_counter; /* ******************************************************************* * @@ -111,6 +116,8 @@ void SystemInit(void) system_busy = false; //Development menu flag devmenu_flag = false; + //Emergency mode flag + emergency_mode = false; GfxSetGlobalLuminance(NORMAL_LUMINANCE); @@ -218,11 +225,101 @@ bool SystemRefreshNeeded(void) void ISR_SystemDefaultVBlank(void) { + if(System1SecondTick() == true) + { + fps = temp_fps; + temp_fps = 0; + } + refresh_needed = true; } /* ******************************************************************* * + * @name: void SystemAcknowledgeFrame(void) + * + * @author: Xavier Del Campo + * + * @brief: + * + * @remarks: + * Called by Game module in order to calculate frames per second. + * + * *******************************************************************/ + +void SystemAcknowledgeFrame(void) +{ + temp_fps++; +} + +/* ******************************************************************* + * + * @name: void SystemAcknowledgeFrame(void) + * + * @author: Xavier Del Campo + * + * @brief: + * Creates a sine-line (more exactly, a parabola-like) effect and + * stores its value into a variable. + * + * @remarks: + * To be called only once, preferibly on SystemCyclic(). + * + * *******************************************************************/ + +void SystemCalculateSine(void) +{ + enum + { + SINE_EFFECT_STEP = 24, + SINE_EFFECT_MAX = 240 + }; + + static bool sine_decrease = false; + + if(sine_decrease == false) + { + if(sine_counter < SINE_EFFECT_MAX) + { + sine_counter += SINE_EFFECT_STEP; + } + else + { + sine_decrease = true; + } + } + else + { + if(sine_counter > SINE_EFFECT_STEP) + { + sine_counter -= SINE_EFFECT_STEP; + } + else + { + sine_decrease = false; + } + } +} + +/* ******************************************************************* + * + * @name: unsigned char SystemGetSineValue(void) + * + * @author: Xavier Del Campo + * + * @return: + * Returns a value which oscillates like a sine (more exactly, like + * a parabola) function to be used wherever you want. + * + * *******************************************************************/ + +unsigned char SystemGetSineValue(void) +{ + return sine_counter; +} + +/* ******************************************************************* + * * @name: void SystemIncreaseGlobalTimer(void) * * @author: Xavier Del Campo @@ -864,6 +961,21 @@ int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t /* **************************************************************************************** * + * @name volatile uint8_t SystemGetFPS(void) + * + * @author: Xavier Del Campo + * + * @return: Frames per second + * + * ****************************************************************************************/ + +volatile uint8_t SystemGetFPS(void) +{ + return fps; +} + +/* **************************************************************************************** + * * @name void SystemCyclicHandler(void) * * @author: Xavier Del Campo @@ -886,6 +998,8 @@ void SystemCyclicHandler(void) SystemDisableScreenRefresh(); MemCardHandler(); + + SystemCalculateSine(); SystemCheckStack(); } diff --git a/Source/System.h b/Source/System.h index cef7b4e..3bce5e4 100644 --- a/Source/System.h +++ b/Source/System.h @@ -105,6 +105,12 @@ int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz); // Function overload for uint8_t data type. int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz); +// Returns frames per second. +volatile uint8_t SystemGetFPS(void); + +// Increase temp_fps in order to calculate frame rate. +void SystemAcknowledgeFrame(void); + void SystemCyclicHandler(void); void SystemClearBuffer(void); @@ -123,6 +129,10 @@ void SystemDevMenuToggle(void); void SystemDevMenu(void); +void SystemCalculateSine(void); + +unsigned char SystemGetSineValue(void); + /* ************************************** * Global Variables * * **************************************/ |
