+ System timer functions now moved to a separate source file, Timer.c/Timer.h.
* Added some more comments on Game.c. * On GamePathToTile(), duplicate checks for existing tile have been replaced by calls to GameWaypointCheckExisting().
This commit is contained in:
parent
b807ee7ca5
commit
f17b15bdff
820
Source/Game.c
820
Source/Game.c
File diff suppressed because it is too large
Load Diff
|
@ -32,7 +32,6 @@ extern TYPE_PLAYER PlayerData[];
|
|||
* *************************************/
|
||||
|
||||
void Game(bool two_players);
|
||||
char* GetGameLevelTitle(void);
|
||||
void GameSetTime(uint8_t hour, uint8_t minutes);
|
||||
bool GameTwoPlayersActive(void);
|
||||
uint8_t GameGetLevelColumns(void);
|
||||
|
@ -41,7 +40,7 @@ fix16_t GameGetYFromTile(uint16_t tile);
|
|||
short GameGetXFromTile_short(uint16_t tile);
|
||||
short GameGetYFromTile_short(uint16_t tile);
|
||||
FL_STATE GameTargetsReached(uint16_t firstTarget, uint8_t index);
|
||||
uint16_t GameGetTileFromIsoPosition(TYPE_ISOMETRIC_POS * IsoPos);
|
||||
uint16_t GameGetTileFromIsoPosition(TYPE_ISOMETRIC_POS* IsoPos);
|
||||
FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx);
|
||||
uint32_t GameGetScore(void);
|
||||
bool GameInsideLevelFromIsoPos(TYPE_ISOMETRIC_FIX16_POS* ptrIsoPos);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Gfx.h"
|
||||
#include "Game.h"
|
||||
#include "LoadMenu.h"
|
||||
#include "Timer.h"
|
||||
|
||||
/* *************************************
|
||||
* Defines
|
||||
|
@ -288,7 +289,7 @@ void GameGuiInit(void)
|
|||
|
||||
PageUpDownSpr.w = AIRCRAFT_DATA_FLIGHT_PAGEUPDN_SIZE;
|
||||
|
||||
ShowAircraftPassengersTimer = SystemCreateTimer(20, true, GameGuiClearPassengersLeft);
|
||||
ShowAircraftPassengersTimer = TimerCreate(20, true, GameGuiClearPassengersLeft);
|
||||
|
||||
slowScore = 0;
|
||||
|
||||
|
@ -617,11 +618,11 @@ void GameGuiBubbleShow(void)
|
|||
if(GameGuiBubbleTimer == NULL)
|
||||
{
|
||||
Serial_printf("Started GameGuiBubbleTimer...\n");
|
||||
GameGuiBubbleTimer = SystemCreateTimer(50, false, &GameGuiBubbleStop);
|
||||
GameGuiBubbleTimer = TimerCreate(50, false, &GameGuiBubbleStop);
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemTimerRestart(GameGuiBubbleTimer);
|
||||
TimerRestart(GameGuiBubbleTimer);
|
||||
}
|
||||
|
||||
GameGuiBubbleShowFlag = true;
|
||||
|
@ -641,11 +642,11 @@ void GameGuiBubble(TYPE_FLIGHT_DATA* ptrFlightData)
|
|||
if(GameGuiBubbleVibrationTimer == NULL)
|
||||
{
|
||||
Serial_printf("Started GameGuiBubbleVibrationTimer...\n");
|
||||
GameGuiBubbleVibrationTimer = SystemCreateTimer(20, false, &GameGuiBubbleStopVibration);
|
||||
GameGuiBubbleVibrationTimer = TimerCreate(20, false, &GameGuiBubbleStopVibration);
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemTimerRestart(GameGuiBubbleVibrationTimer);
|
||||
TimerRestart(GameGuiBubbleVibrationTimer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -593,7 +593,7 @@ bool GfxTPageOffsetFromVRAMPosition(GsSprite * spr, short x, short y)
|
|||
return false;
|
||||
}
|
||||
|
||||
TYPE_CARTESIAN_POS GfxIsometricToCartesian(TYPE_ISOMETRIC_POS * ptrIsoPos)
|
||||
TYPE_CARTESIAN_POS GfxIsometricToCartesian(TYPE_ISOMETRIC_POS* ptrIsoPos)
|
||||
{
|
||||
TYPE_CARTESIAN_POS retCartPos;
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ void GfxDrawButton(short x, short y, unsigned short btn);
|
|||
// sprite structure pointed to by "spr".
|
||||
void GfxSaveDisplayData(GsSprite *spr);
|
||||
|
||||
TYPE_CARTESIAN_POS GfxIsometricToCartesian(TYPE_ISOMETRIC_POS * ptrIsoPos);
|
||||
TYPE_CARTESIAN_POS GfxIsometricToCartesian(TYPE_ISOMETRIC_POS* ptrIsoPos);
|
||||
// Function overload for fixed-point 16.16 data type.
|
||||
|
||||
TYPE_CARTESIAN_POS GfxIsometricFix16ToCartesian(TYPE_ISOMETRIC_FIX16_POS * ptrIso16Pos);
|
||||
|
|
|
@ -35,11 +35,11 @@ GNU_SIZE = mipsel-unknown-elf-size
|
|||
OBJECTS = $(addprefix $(OBJ_DIR)/,main.o System.o Menu.o Gfx.o Pad.o MainMenuBtnAni.o \
|
||||
LoadMenu.o GameGui.o Sfx.o Camera.o EndAnimation.o \
|
||||
PSXSDKIntro.o PltParser.o Game.o Font.o MemCard.o \
|
||||
Aircraft.o Serial.o)
|
||||
Aircraft.o Serial.o Timer.o)
|
||||
|
||||
DEPS = $(OBJECTS:.o=.d)
|
||||
|
||||
build: levels $(PROJECT).bin
|
||||
build: levels $(PROJECT).bin
|
||||
|
||||
rebuild: clean build
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "Pad.h"
|
||||
#include "System.h"
|
||||
#include "Timer.h"
|
||||
|
||||
/* *************************************
|
||||
* Defines
|
||||
|
@ -456,8 +457,8 @@ void PadClearData(void)
|
|||
|
||||
void PadInit(void)
|
||||
{
|
||||
pad1_cheat_timer = SystemCreateTimer(PAD_CHEAT_TIMEOUT,true /* Repeat flag */,&PadOneCleanCheatArray);
|
||||
pad2_cheat_timer = SystemCreateTimer(PAD_CHEAT_TIMEOUT,true /* Repeat flag */,&PadTwoCleanCheatArray);
|
||||
pad1_cheat_timer = TimerCreate(PAD_CHEAT_TIMEOUT,true /* Repeat flag */,&PadOneCleanCheatArray);
|
||||
pad2_cheat_timer = TimerCreate(PAD_CHEAT_TIMEOUT,true /* Repeat flag */,&PadTwoCleanCheatArray);
|
||||
|
||||
memset(cheatsArray,0, sizeof(cheatsArray));
|
||||
}
|
||||
|
@ -524,7 +525,7 @@ void PadCheatHandler(uint8_t n_pad)
|
|||
{
|
||||
if(pressed_callback(available_keys[i]) == true)
|
||||
{
|
||||
SystemTimerRestart(timer);
|
||||
TimerRestart(timer);
|
||||
key = available_keys[i];
|
||||
keys_released++;
|
||||
}
|
||||
|
|
158
Source/System.c
158
Source/System.c
|
@ -8,13 +8,13 @@
|
|||
#include "Gfx.h"
|
||||
#include "MemCard.h"
|
||||
#include "EndAnimation.h"
|
||||
#include "Timer.h"
|
||||
|
||||
/* *************************************
|
||||
* Defines
|
||||
* *************************************/
|
||||
|
||||
#define FILE_BUFFER_SIZE 0x20014
|
||||
#define SYSTEM_MAX_TIMERS 16
|
||||
|
||||
#define END_STACK_PATTERN (uint32_t) 0x18022015
|
||||
#define BEGIN_STACK_ADDRESS (uint32_t*) 0x801FFF00
|
||||
|
@ -49,8 +49,6 @@ static bool five_hundred_ms_timer;
|
|||
static bool emergency_mode;
|
||||
//Critical section is entered (i.e.: when accessing fopen() or other BIOS functions
|
||||
static volatile bool system_busy;
|
||||
//Timer array.
|
||||
static TYPE_TIMER timer_array[SYSTEM_MAX_TIMERS];
|
||||
// When true, it draws a rectangle on top of all primitives with
|
||||
// information for development purposes.
|
||||
static bool devmenu_flag;
|
||||
|
@ -96,7 +94,7 @@ void SystemInit(void)
|
|||
//SPU init
|
||||
SsInit();
|
||||
//Reset all user-handled timers
|
||||
SystemResetTimers();
|
||||
TimerReset();
|
||||
//Pads init
|
||||
PadInit();
|
||||
//Set Drawing Environment
|
||||
|
@ -665,156 +663,6 @@ bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* ********************************************************************************************
|
||||
*
|
||||
* @name TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void) )
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: fills a TYPE_TIMER structure with input parameters
|
||||
*
|
||||
* @param: uint32_t t:
|
||||
* Timeout value (1 unit = 10 ms)
|
||||
* bool rf:
|
||||
* Repeat flag
|
||||
* void (*timer_callback)(void)
|
||||
* Function to be called on timeout
|
||||
*
|
||||
* @return: pointer to TYPE_TIMER structure if filled correctly, NULL pointer otherwise.
|
||||
*
|
||||
* ********************************************************************************************/
|
||||
|
||||
TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void) )
|
||||
{
|
||||
bool success = false;
|
||||
uint8_t i;
|
||||
|
||||
if(t == 0)
|
||||
{
|
||||
Serial_printf("Cannot create timer with time == 0!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i < SYSTEM_MAX_TIMERS; i++)
|
||||
{
|
||||
if(timer_array[i].busy == false)
|
||||
{
|
||||
timer_array[i].Timeout_Callback = timer_callback;
|
||||
timer_array[i].time = t;
|
||||
timer_array[i].orig_time = t;
|
||||
timer_array[i].repeat_flag = rf;
|
||||
timer_array[i].busy = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(success == false)
|
||||
{
|
||||
Serial_printf("Could not find any free timer!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &timer_array[i];
|
||||
}
|
||||
|
||||
/* *******************************************
|
||||
*
|
||||
* @name void SystemResetTimers(void)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: reportedly, removes all timers.
|
||||
*
|
||||
* *******************************************/
|
||||
|
||||
void SystemResetTimers(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < SYSTEM_MAX_TIMERS; i++)
|
||||
{
|
||||
SystemTimerRemove(&timer_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* *****************************************************
|
||||
*
|
||||
* @name void SystemUserTimersHandler(void)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: reportedly, handles all available timers.
|
||||
*
|
||||
* @remarks: calls callback on timeout.
|
||||
*
|
||||
* *****************************************************/
|
||||
|
||||
void SystemUserTimersHandler(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < SYSTEM_MAX_TIMERS; i++)
|
||||
{
|
||||
if(timer_array[i].busy == true)
|
||||
{
|
||||
if(System100msTick() == true)
|
||||
{
|
||||
timer_array[i].time--;
|
||||
|
||||
if(timer_array[i].time == 0)
|
||||
{
|
||||
timer_array[i].Timeout_Callback();
|
||||
|
||||
if(timer_array[i].repeat_flag == true)
|
||||
{
|
||||
timer_array[i].time = timer_array[i].orig_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* *********************************************************************
|
||||
*
|
||||
* @name void SystemUserTimersHandler(void)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: sets time left for TYPE_TIMER instance to initial value.
|
||||
*
|
||||
* @remarks: specially used when TYPE_TIMER.rf is enabled.
|
||||
*
|
||||
* *********************************************************************/
|
||||
|
||||
void SystemTimerRestart(TYPE_TIMER* timer)
|
||||
{
|
||||
timer->time = timer->orig_time;
|
||||
}
|
||||
|
||||
/* *********************************************************************
|
||||
*
|
||||
* @name void SystemTimerRemove(TYPE_TIMER* timer)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: Resets timer parameters to default values so timer instance
|
||||
* can be recycled.
|
||||
*
|
||||
* @remarks:
|
||||
*
|
||||
* *********************************************************************/
|
||||
|
||||
void SystemTimerRemove(TYPE_TIMER* timer)
|
||||
{
|
||||
timer->time = 0;
|
||||
timer->orig_time = 0;
|
||||
timer->Timeout_Callback = NULL;
|
||||
timer->busy = false;
|
||||
timer->repeat_flag = false;
|
||||
}
|
||||
|
||||
/* ****************************************************************************************
|
||||
*
|
||||
* @name bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz)
|
||||
|
@ -1028,7 +876,7 @@ void SystemCyclicHandler(void)
|
|||
|
||||
SystemRunTimers();
|
||||
|
||||
SystemUserTimersHandler();
|
||||
TimerHandler();
|
||||
|
||||
SystemDisableScreenRefresh();
|
||||
|
||||
|
|
|
@ -85,23 +85,6 @@ bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz);
|
|||
// Overload for uint16_t
|
||||
bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz);
|
||||
|
||||
// Creates a timer instance wiht a determined value and associates it to a callback
|
||||
// Once time expires, callback is automatically called right after GfxDrawScene().
|
||||
// Time is expressed so that t = 100 ms e.g.: 2 seconds = 20.
|
||||
TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void) );
|
||||
|
||||
// Reportedly, sets all timer data to zero.
|
||||
void SystemResetTimers(void);
|
||||
|
||||
// To be called every cycle (i.e.: inside GfxDrawScene() ).
|
||||
void SystemUserTimersHandler(void);
|
||||
|
||||
// Sets timer remaining time to initial value.
|
||||
void SystemTimerRestart(TYPE_TIMER* timer);
|
||||
|
||||
// Flushes a timer pointed to by timer.
|
||||
void SystemTimerRemove(TYPE_TIMER* timer);
|
||||
|
||||
// Compares two arrays of unsigned short type.
|
||||
bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz);
|
||||
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
/* *************************************
|
||||
* Includes
|
||||
* *************************************/
|
||||
|
||||
#include "Timer.h"
|
||||
#include "GameStructures.h"
|
||||
|
||||
/* *************************************
|
||||
* Defines
|
||||
* *************************************/
|
||||
|
||||
#define MAX_TIMERS 16
|
||||
|
||||
/* *************************************
|
||||
* Local Variables
|
||||
* *************************************/
|
||||
|
||||
//Timer array.
|
||||
static TYPE_TIMER timer_array[MAX_TIMERS];
|
||||
|
||||
/* *************************************
|
||||
* Local Prototypes
|
||||
* *************************************/
|
||||
|
||||
/* ********************************************************************************************
|
||||
*
|
||||
* @name TYPE_TIMER* TimerCreate(uint32_t t, bool rf, void (*timer_callback)(void) )
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: fills a TYPE_TIMER structure with input parameters
|
||||
*
|
||||
* @param: uint32_t t:
|
||||
* Timeout value (1 unit = 10 ms)
|
||||
* bool rf:
|
||||
* Repeat flag
|
||||
* void (*timer_callback)(void)
|
||||
* Function to be called on timeout
|
||||
*
|
||||
* @return: pointer to TYPE_TIMER structure if filled correctly, NULL pointer otherwise.
|
||||
*
|
||||
* ********************************************************************************************/
|
||||
|
||||
TYPE_TIMER* TimerCreate(uint32_t t, bool rf, void (*timer_callback)(void) )
|
||||
{
|
||||
bool success = false;
|
||||
uint8_t i;
|
||||
|
||||
if(t == 0)
|
||||
{
|
||||
Serial_printf("Cannot create timer with time == 0!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i < MAX_TIMERS; i++)
|
||||
{
|
||||
if(timer_array[i].busy == false)
|
||||
{
|
||||
timer_array[i].Timeout_Callback = timer_callback;
|
||||
timer_array[i].time = t;
|
||||
timer_array[i].orig_time = t;
|
||||
timer_array[i].repeat_flag = rf;
|
||||
timer_array[i].busy = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(success == false)
|
||||
{
|
||||
Serial_printf("Could not find any free timer!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &timer_array[i];
|
||||
}
|
||||
|
||||
/* *******************************************
|
||||
*
|
||||
* @name void TimerReset(void)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: reportedly, removes all timers.
|
||||
*
|
||||
* *******************************************/
|
||||
|
||||
void TimerReset(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < MAX_TIMERS; i++)
|
||||
{
|
||||
TimerRemove(&timer_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* *****************************************************
|
||||
*
|
||||
* @name void TimerHandler(void)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: reportedly, handles all available timers.
|
||||
*
|
||||
* @remarks: calls callback on timeout.
|
||||
*
|
||||
* *****************************************************/
|
||||
|
||||
void TimerHandler(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < MAX_TIMERS; i++)
|
||||
{
|
||||
if(timer_array[i].busy == true)
|
||||
{
|
||||
if(System100msTick() == true)
|
||||
{
|
||||
timer_array[i].time--;
|
||||
|
||||
if(timer_array[i].time == 0)
|
||||
{
|
||||
timer_array[i].Timeout_Callback();
|
||||
|
||||
if(timer_array[i].repeat_flag == true)
|
||||
{
|
||||
timer_array[i].time = timer_array[i].orig_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* *********************************************************************
|
||||
*
|
||||
* @name void TimerRestart(TYPE_TIMER* timer)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: sets time left for TYPE_TIMER instance to initial value.
|
||||
*
|
||||
* @remarks: specially used when TYPE_TIMER.rf is enabled.
|
||||
*
|
||||
* *********************************************************************/
|
||||
|
||||
void TimerRestart(TYPE_TIMER* timer)
|
||||
{
|
||||
timer->time = timer->orig_time;
|
||||
}
|
||||
|
||||
/* *********************************************************************
|
||||
*
|
||||
* @name void TimerRemove(TYPE_TIMER* timer)
|
||||
*
|
||||
* @author: Xavier Del Campo
|
||||
*
|
||||
* @brief: Resets timer parameters to default values so timer instance
|
||||
* can be recycled.
|
||||
*
|
||||
* @remarks:
|
||||
*
|
||||
* *********************************************************************/
|
||||
|
||||
void TimerRemove(TYPE_TIMER* timer)
|
||||
{
|
||||
timer->time = 0;
|
||||
timer->orig_time = 0;
|
||||
timer->Timeout_Callback = NULL;
|
||||
timer->busy = false;
|
||||
timer->repeat_flag = false;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef __TIMER_HEADER__
|
||||
#define __TIMER_HEADER__
|
||||
|
||||
/* **************************************
|
||||
* Includes *
|
||||
* **************************************/
|
||||
|
||||
#include "Global_Inc.h"
|
||||
#include "GameStructures.h"
|
||||
|
||||
/* **************************************
|
||||
* Defines *
|
||||
* **************************************/
|
||||
|
||||
/* **************************************
|
||||
* Global Prototypes *
|
||||
* **************************************/
|
||||
|
||||
// Creates a timer instance wiht a determined value and associates it to a callback
|
||||
// Once time expires, callback is automatically called right after GfxDrawScene().
|
||||
// Time is expressed so that t = 100 ms e.g.: 2 seconds = 20.
|
||||
TYPE_TIMER* TimerCreate(uint32_t t, bool rf, void (*timer_callback)(void) );
|
||||
|
||||
// Reportedly, sets all timer data to zero.
|
||||
void TimerReset(void);
|
||||
|
||||
// To be called every cycle (i.e.: inside GfxDrawScene() ).
|
||||
void TimerHandler(void);
|
||||
|
||||
// Sets timer remaining time to initial value.
|
||||
void TimerRestart(TYPE_TIMER* timer);
|
||||
|
||||
// Flushes a timer pointed to by timer.
|
||||
void TimerRemove(TYPE_TIMER* timer);
|
||||
|
||||
#endif // __TIMER_HEADER__
|
Loading…
Reference in New Issue