aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-06-03 01:37:55 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-06-03 01:37:55 +0200
commit219d958538aecfec4dace7f3b31dcfa193667b27 (patch)
tree148bb1758f5015facf6d74fdf71d20915e7b098d /Source
parent92c65ff3b240678ab864e4eb574e02f6151bdbe4 (diff)
downloadairport-219d958538aecfec4dace7f3b31dcfa193667b27.tar.gz
* More passengers by correct sequence are unboarded.
* Aircraft should not be removed on State == STATE_APPROACH. * Initial implementation for finished game. * Added some comments on System.c. * GameGuiPrepareNotificationString() deprecated.
Diffstat (limited to 'Source')
-rw-r--r--Source/Aircraft.c3
-rw-r--r--Source/Game.c71
-rw-r--r--Source/GameGui.c240
-rw-r--r--Source/GameGui.h2
-rw-r--r--Source/MainMenuBtnAni.c2
-rw-r--r--Source/MainMenuBtnAni.h3
-rw-r--r--Source/Makefile3
-rw-r--r--Source/Menu.c2
-rw-r--r--Source/PltParser.c1
-rw-r--r--Source/System.c256
10 files changed, 385 insertions, 198 deletions
diff --git a/Source/Aircraft.c b/Source/Aircraft.c
index c2932c5..468adba 100644
--- a/Source/Aircraft.c
+++ b/Source/Aircraft.c
@@ -114,6 +114,8 @@ bool AircraftAddNew( TYPE_FLIGHT_DATA * ptrFlightData,
ptrAircraft->FlightDataIdx = FlightDataIndex;
+ dprintf("ptrAircraft->FlightDataIdx = %d, FlightDataIndex = %d\n", ptrAircraft->FlightDataIdx, FlightDataIndex);
+
if(ptrFlightData->FlightDirection[FlightDataIndex] == ARRIVAL)
{
ptrAircraft->IsoPos.x = 0;
@@ -386,6 +388,7 @@ void AircraftDirection(TYPE_AIRCRAFT_DATA* ptrAircraft)
{
dprintf("All targets reached!\n");
ptrAircraft->State = GameTargetsReached(ptrAircraft->Target[0], ptrAircraft->FlightDataIdx);
+ memset(ptrAircraft->Target, 0, AIRCRAFT_MAX_TARGETS);
}
}
}
diff --git a/Source/Game.c b/Source/Game.c
index 19db3b6..97cc9d5 100644
--- a/Source/Game.c
+++ b/Source/Game.c
@@ -105,7 +105,7 @@ enum
UNBOARDING_KEY_SEQUENCE_EASY = 4,
UNBOARDING_KEY_SEQUENCE_MEDIUM = 6,
UNBOARDING_KEY_SEQUENCE_HARD = GAME_MAX_SEQUENCE_KEYS,
- UNBOARDING_PASSENGERS_PER_SEQUENCE = 25
+ UNBOARDING_PASSENGERS_PER_SEQUENCE = 50
};
/* *************************************
@@ -115,6 +115,7 @@ enum
static void GameInit(void);
static void GameLoadLevel(void);
static bool GamePause(void);
+static bool GameFinished(void);
static void GameEmergencyMode(void);
static void GameCalculations(void);
static void GamePlayerHandler(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData);
@@ -212,6 +213,11 @@ void Game(bool two_players)
while(1)
{
+ if(GameFinished() == true)
+ {
+ break;
+ }
+
if(GamePause() == true)
{
// Exit game
@@ -665,8 +671,6 @@ void GameGraphics(void)
// Draw common elements for both players (messages, clock...)
- GameGuiAircraftNotificationRequest(&FlightData);
-
GameGuiBubble(&FlightData);
GameGuiClock(GameHour,GameMinutes);
@@ -804,6 +808,8 @@ void GameAircraftState(void)
target[0] = FlightData.Parking[i];
dprintf("Target assigned = %d\n", target[0]);
+
+ dprintf("2\n");
if(AircraftAddNew(&FlightData, i, target) == false)
{
@@ -814,6 +820,7 @@ void GameAircraftState(void)
}
else if(FlightData.FlightDirection[i] == ARRIVAL)
{
+ dprintf("Flight %d set to STATE_APPROACH.\n", i);
FlightData.State[i] = STATE_APPROACH;
// Create notification request for incoming aircraft
FlightData.NotificationRequest[i] = true;
@@ -825,6 +832,9 @@ void GameAircraftState(void)
(FlightData.RemainingTime[i] == 0) )
{
// Player(s) lost a flight!
+ DEBUG_PRINT_VAR(i);
+ DEBUG_PRINT_VAR(FlightData.State[i]);
+ DEBUG_PRINT_VAR(FlightData.RemainingTime[i]);
GameRemoveFlight(i, false);
}
}
@@ -1007,11 +1017,27 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
for(j = 0; j < GAME_MAX_AIRCRAFT; j++)
{
+ uint16_t* targets = AircraftGetTargets(j);
aircraftTile = AircraftGetTileFromFlightDataIndex(j);
+ uint16_t lastTarget = 0;
+ uint8_t k;
- if(i == aircraftTile)
+ for(k = 0; k < AIRCRAFT_MAX_TARGETS; k++)
+ {
+ if(targets[k] == 0)
+ {
+ break;
+ }
+
+ lastTarget = targets[k];
+ }
+
+ if( (i == aircraftTile)
+ ||
+ (i == lastTarget) )
{
bHoldingRwyBusy = true;
+ break;
}
}
@@ -1704,6 +1730,8 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFl
targets[0] = assignedRwy;
targets[1] = rwyExit;
+
+ dprintf("1\n");
if( AircraftAddNew(ptrFlightData,
aircraftIndex,
@@ -2460,24 +2488,22 @@ void GameRemoveFlight(uint8_t idx, bool successful)
DEBUG_PRINT_VAR(&PlayerData[PLAYER_ONE]);
DEBUG_PRINT_VAR(&PlayerData[PLAYER_TWO]);*/
- FlightData.Passengers[ptrPlayer->ActiveAircraftList[j]] = 0;
- FlightData.State[ptrPlayer->ActiveAircraftList[j]] = STATE_IDLE;
- FlightData.Finished[ptrPlayer->ActiveAircraftList[j]] = true;
-
for(k = 0; k < GAME_MAX_RUNWAYS; k++)
{
uint16_t* targets = AircraftGetTargets(ptrPlayer->ActiveAircraftList[j]);
- uint8_t targetIdx = AircraftGetTargetIdx(ptrPlayer->ActiveAircraftList[j]);
- if(SystemContains_u16(GameUsedRwy[k], targets, targetIdx) == true)
+ if(SystemContains_u16(GameUsedRwy[k], targets, AIRCRAFT_MAX_TARGETS) == true)
{
GameUsedRwy[k] = 0;
}
}
-
- if(AircraftRemove(idx) == false)
+
+ if(FlightData.State[ptrPlayer->ActiveAircraftList[j]] != STATE_APPROACH)
{
- dprintf("Something went wrong when removing aircraft!\n");
+ if(AircraftRemove(idx) == false)
+ {
+ dprintf("Something went wrong when removing aircraft!\n");
+ }
}
ptrPlayer->LockTarget = false;
@@ -2492,6 +2518,10 @@ void GameRemoveFlight(uint8_t idx, bool successful)
GameScore = (GameScore < LOST_FLIGHT_PENALTY)? 0 : (GameScore - LOST_FLIGHT_PENALTY);
}
+ FlightData.Passengers[ptrPlayer->ActiveAircraftList[j]] = 0;
+ FlightData.State[ptrPlayer->ActiveAircraftList[j]] = STATE_IDLE;
+ FlightData.Finished[ptrPlayer->ActiveAircraftList[j]] = true;
+
return;
}
}
@@ -2525,3 +2555,18 @@ void GameActiveAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlight
}
}
+bool GameFinished(void)
+{
+ uint8_t i;
+
+ for(i = 0; i < FlightData.nAircraft; i++)
+ {
+ if(FlightData.Finished[i] == false)
+ {
+ // At least one aircraft still not finished
+ return false;
+ }
+ }
+
+ return GameGuiFinishedDialog(&PlayerData[PLAYER_ONE]);
+}
diff --git a/Source/GameGui.c b/Source/GameGui.c
index b670dfa..4e6efdc 100644
--- a/Source/GameGui.c
+++ b/Source/GameGui.c
@@ -10,7 +10,6 @@
#define NOTIFICATION_TIMER_LIMIT 5*TIMEBASE_1_SECOND // 5 seconds
#define BUBBLE_VIBRATION_TIMER_LIMIT TIMEBASE_1_SECOND >> 1 // Half a second
-#define NOTIFICATION_BUFFER_SIZE 200
#define GAME_GUI_AIRCRAFT_DATA_MAX_PAGE 4
#define SLOW_SCORE_LOW_SPEED_MARGIN 100
@@ -20,57 +19,6 @@
/* **************************************
* Structs and enums *
* *************************************/
-
-enum
-{
- PAUSE_DIALOG_X = 92,
- PAUSE_DIALOG_Y = 28,
- PAUSE_DIALOG_W = 200,
- PAUSE_DIALOG_H = 184,
-
- PAUSE_DIALOG_R0 = 0,
- PAUSE_DIALOG_R1 = PAUSE_DIALOG_R0,
- PAUSE_DIALOG_R2 = 0,
- PAUSE_DIALOG_R3 = PAUSE_DIALOG_R2,
-
- PAUSE_DIALOG_G0 = NORMAL_LUMINANCE,
- PAUSE_DIALOG_G1 = PAUSE_DIALOG_G0,
- PAUSE_DIALOG_G2 = 0,
- PAUSE_DIALOG_G3 = PAUSE_DIALOG_G2,
-
- PAUSE_DIALOG_B0 = 40,
- PAUSE_DIALOG_B1 = PAUSE_DIALOG_B0,
- PAUSE_DIALOG_B2 = 0,
- PAUSE_DIALOG_B3 = PAUSE_DIALOG_B2,
-};
-
-enum
-{
- NOTIFICATION_GSGPOLY4_R0 = 0,
- NOTIFICATION_GSGPOLY4_R1 = NOTIFICATION_GSGPOLY4_R0,
- NOTIFICATION_GSGPOLY4_R2 = 0,
- NOTIFICATION_GSGPOLY4_R3 = NOTIFICATION_GSGPOLY4_R2,
-
- NOTIFICATION_GSGPOLY4_G0 = NORMAL_LUMINANCE,
- NOTIFICATION_GSGPOLY4_G1 = NOTIFICATION_GSGPOLY4_G0,
- NOTIFICATION_GSGPOLY4_G2 = 0,
- NOTIFICATION_GSGPOLY4_G3 = NOTIFICATION_GSGPOLY4_G2,
-
- NOTIFICATION_GSGPOLY4_B0 = 40,
- NOTIFICATION_GSGPOLY4_B1 = NOTIFICATION_GSGPOLY4_B0,
- NOTIFICATION_GSGPOLY4_B2 = 0,
- NOTIFICATION_GSGPOLY4_B3 = NOTIFICATION_GSGPOLY4_B2,
-
- NOTIFICATION_GSGPOLY4_X0 = 16,
- NOTIFICATION_GSGPOLY4_X1 = X_SCREEN_RESOLUTION - NOTIFICATION_GSGPOLY4_X0 - 16,
- NOTIFICATION_GSGPOLY4_X2 = NOTIFICATION_GSGPOLY4_X0,
- NOTIFICATION_GSGPOLY4_X3 = NOTIFICATION_GSGPOLY4_X1,
-
- NOTIFICATION_GSGPOLY4_Y0 = Y_SCREEN_RESOLUTION - (64 + 8),
- NOTIFICATION_GSGPOLY4_Y1 = NOTIFICATION_GSGPOLY4_Y0,
- NOTIFICATION_GSGPOLY4_Y2 = Y_SCREEN_RESOLUTION - 8,
- NOTIFICATION_GSGPOLY4_Y3 = NOTIFICATION_GSGPOLY4_Y2
-};
enum
{
@@ -85,18 +33,6 @@ enum
enum
{
- CLOCK_X = 16,
- CLOCK_Y = 16
-};
-
-enum
-{
- SCORE_X = (X_SCREEN_RESOLUTION >> 1) - 64,
- SCORE_Y = 16,
-};
-
-enum
-{
AIRCRAFT_DATA_GSGPOLY4_R0 = 0,
AIRCRAFT_DATA_GSGPOLY4_R1 = AIRCRAFT_DATA_GSGPOLY4_R0,
AIRCRAFT_DATA_GSGPOLY4_R2 = 0,
@@ -236,7 +172,6 @@ enum
* Local prototypes *
* *************************************/
-static void GameGuiPrepareNotificationString(TYPE_FLIGHT_DATA * ptrFlightData, uint8_t offset);
static void GameGuiShowAircraftData(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData);
static void GameGuiClearPassengersLeft(void);
@@ -245,7 +180,6 @@ static void GameGuiClearPassengersLeft(void);
* *************************************/
static GsSprite BubbleSpr;
-static GsGPoly4 NotificationGPoly4;
static GsGPoly4 AircraftDataGPoly4;
static GsGPoly4 SelectedAircraftGPoly4;
static GsSprite ArrowsSpr;
@@ -262,11 +196,33 @@ static void * GameFileDest[] = {(GsSprite*)&BubbleSpr ,
(TYPE_FONT*)&RadioFont ,
(GsSprite*)&ArrowsSpr };
-static char strNotificationRequest[NOTIFICATION_BUFFER_SIZE];
static uint32_t slowScore; // It will update slowly to actual score value
void GameGuiInit(void)
{
+ enum
+ {
+ PAUSE_DIALOG_X = 92,
+ PAUSE_DIALOG_Y = 28,
+ PAUSE_DIALOG_W = 200,
+ PAUSE_DIALOG_H = 184,
+
+ PAUSE_DIALOG_R0 = 0,
+ PAUSE_DIALOG_R1 = PAUSE_DIALOG_R0,
+ PAUSE_DIALOG_R2 = 0,
+ PAUSE_DIALOG_R3 = PAUSE_DIALOG_R2,
+
+ PAUSE_DIALOG_G0 = NORMAL_LUMINANCE,
+ PAUSE_DIALOG_G1 = PAUSE_DIALOG_G0,
+ PAUSE_DIALOG_G2 = 0,
+ PAUSE_DIALOG_G3 = PAUSE_DIALOG_G2,
+
+ PAUSE_DIALOG_B0 = 40,
+ PAUSE_DIALOG_B1 = PAUSE_DIALOG_B0,
+ PAUSE_DIALOG_B2 = 0,
+ PAUSE_DIALOG_B3 = PAUSE_DIALOG_B2,
+ };
+
LoadMenu( GameFileList,
GameFileDest,
sizeof(GameFileList) / sizeof(char*),
@@ -304,89 +260,6 @@ void GameGuiInit(void)
slowScore = 0;
}
-void GameGuiAircraftNotificationRequest(TYPE_FLIGHT_DATA * ptrFlightData)
-{
- uint8_t i;
- static uint16_t NotificationTimer;
- static uint8_t FirstNotification;
- bool first_entered = true;
-
- if(GameStartupFlag == true)
- {
- // Set initial values to static variables
- NotificationTimer = 0;
- FirstNotification = 0;
- }
-
- for(i = FirstNotification; i < ptrFlightData->nAircraft ; i++)
- {
- if(ptrFlightData->NotificationRequest[i] == true)
- {
- // Prepare RGB data and (X,Y) coordinates for notification
- // request rectangle.
- NotificationGPoly4.r[0] = NOTIFICATION_GSGPOLY4_R0;
- NotificationGPoly4.r[1] = NOTIFICATION_GSGPOLY4_R1;
- NotificationGPoly4.r[2] = NOTIFICATION_GSGPOLY4_R2;
- NotificationGPoly4.r[3] = NOTIFICATION_GSGPOLY4_R3;
-
- NotificationGPoly4.g[0] = NOTIFICATION_GSGPOLY4_G0;
- NotificationGPoly4.g[1] = NOTIFICATION_GSGPOLY4_G1;
- NotificationGPoly4.g[2] = NOTIFICATION_GSGPOLY4_G2;
- NotificationGPoly4.g[3] = NOTIFICATION_GSGPOLY4_G3;
-
- NotificationGPoly4.b[0] = NOTIFICATION_GSGPOLY4_B0;
- NotificationGPoly4.b[1] = NOTIFICATION_GSGPOLY4_B1;
- NotificationGPoly4.b[2] = NOTIFICATION_GSGPOLY4_B2;
- NotificationGPoly4.b[3] = NOTIFICATION_GSGPOLY4_B3;
-
- NotificationGPoly4.attribute |= ENABLE_TRANS | TRANS_MODE(0);
-
- NotificationGPoly4.x[0] = NOTIFICATION_GSGPOLY4_X0;
- NotificationGPoly4.x[1] = NOTIFICATION_GSGPOLY4_X1;
- NotificationGPoly4.x[2] = NOTIFICATION_GSGPOLY4_X2;
- NotificationGPoly4.x[3] = NOTIFICATION_GSGPOLY4_X3;
-
- NotificationGPoly4.y[0] = NOTIFICATION_GSGPOLY4_Y0;
- NotificationGPoly4.y[1] = NOTIFICATION_GSGPOLY4_Y1;
- NotificationGPoly4.y[2] = NOTIFICATION_GSGPOLY4_Y2;
- NotificationGPoly4.y[3] = NOTIFICATION_GSGPOLY4_Y3;
-
- /* dprintf("Notification timer: %d.\n",NotificationTimer); */
-
- if(++NotificationTimer >= NOTIFICATION_TIMER_LIMIT)
- {
- // Reset timer and notification request for current aircraft
- FirstNotification = 0;
- NotificationTimer = 0;
- ptrFlightData->NotificationRequest[i] = 0;
- first_entered = true;
- }
- else
- {
- if(first_entered == true)
- {
- // Prepare string for new notification request only once
- first_entered = false;
- RadioFont.max_ch_wrap = 18;
- RadioFont.flags |= FONT_WRAP_LINE;
- GameGuiPrepareNotificationString(ptrFlightData, i);
- }
-
- // Keep information about last aircraft notified...
- // so that it gets called on next cycle
- FirstNotification = i;
- GsSortGPoly4(&NotificationGPoly4);
- FontPrintText( &RadioFont,
- NotificationGPoly4.x[0] + 8,
- NotificationGPoly4.y[0] + 8,
- strNotificationRequest);
- }
-
- break;
- }
- }
-}
-
bool GameGuiPauseDialog(TYPE_PLAYER* ptrPlayer)
{
GfxSaveDisplayData(&SecondDisplay);
@@ -717,30 +590,14 @@ void GameGuiBubble(TYPE_FLIGHT_DATA * ptrFlightData)
//dprintf("Bubble timer: %d\n",BubbleVibrationTimer);
}
-void GameGuiPrepareNotificationString(TYPE_FLIGHT_DATA * ptrFlightData, uint8_t offset)
+void GameGuiClock(uint8_t hour, uint8_t min)
{
- memset(strNotificationRequest,0,NOTIFICATION_BUFFER_SIZE);
- strncat( strNotificationRequest,
- ptrFlightData->strFlightNumber[offset],
- strlen(ptrFlightData->strFlightNumber[offset]) );
-
- strcat(strNotificationRequest, " request for ");
-
- switch(ptrFlightData->FlightDirection[offset])
+ enum
{
- case DEPARTURE:
- strcat(strNotificationRequest, "departure");
- break;
- case ARRIVAL:
- strcat(strNotificationRequest, "approach");
- break;
- }
-
- strcat(strNotificationRequest, ".");
-}
+ CLOCK_X = 16,
+ CLOCK_Y = 4
+ };
-void GameGuiClock(uint8_t hour, uint8_t min)
-{
static char strClock[6]; // HH:MM + \0 (6 characters needed)
if(GameStartupFlag || System1SecondTick() == true)
@@ -967,6 +824,12 @@ void GameGuiCalculateSlowScore(void)
void GameGuiShowScore(void)
{
+ enum
+ {
+ SCORE_X = (X_SCREEN_RESOLUTION >> 1) - 64,
+ SCORE_Y = 4,
+ };
+
FontPrintText( &RadioFont,
SCORE_X,
SCORE_Y,
@@ -1003,3 +866,38 @@ void GameGuiClearPassengersLeft(void)
{
GameGuiClearPassengersLeft_Flag = true;
}
+
+bool GameGuiFinishedDialog(TYPE_PLAYER* ptrPlayer)
+{
+ GfxSaveDisplayData(&SecondDisplay);
+
+ GfxSetGlobalLuminance(NORMAL_LUMINANCE);
+
+ //DrawFBRect(0, 0, X_SCREEN_RESOLUTION, VRAM_H, 0, 0, 0);
+
+ while(GfxIsGPUBusy() == true);
+
+ do
+ {
+ if(ptrPlayer->PadKeySinglePress_Callback(PAD_CROSS) == true)
+ {
+ return true;
+ }
+
+ GfxSortSprite(&SecondDisplay);
+
+ GsSortGPoly4(&PauseRect);
+
+ FontPrintText( &SmallFont,
+ AIRCRAFT_DATA_GSGPOLY4_X0_2PLAYER +
+ ( (AIRCRAFT_DATA_GSGPOLY4_X1_2PLAYER - AIRCRAFT_DATA_GSGPOLY4_X0_2PLAYER) >> 2),
+ AIRCRAFT_DATA_GSGPOLY4_Y0_2PLAYER +
+ ( (AIRCRAFT_DATA_GSGPOLY4_Y2_2PLAYER - AIRCRAFT_DATA_GSGPOLY4_Y0_2PLAYER) >> 1),
+ "All flights finished!" );
+
+ GfxDrawScene_Slow();
+
+ }while(ptrPlayer->PadKeySinglePress_Callback(PAD_START) == false);
+
+ return false;
+}
diff --git a/Source/GameGui.h b/Source/GameGui.h
index bae15ef..3e9ca87 100644
--- a/Source/GameGui.h
+++ b/Source/GameGui.h
@@ -30,7 +30,6 @@
void GameGuiInit(void);
bool GameGuiPauseDialog(TYPE_PLAYER* ptrPlayer);
bool GameGuiShowAircraftDataSpecialConditions(TYPE_PLAYER* ptrPlayer);
-void GameGuiAircraftNotificationRequest(TYPE_FLIGHT_DATA * ptrFlightData);
void GameGuiBubble(TYPE_FLIGHT_DATA * ptrFlightData);
void GameGuiClock(uint8_t hour, uint8_t min);
void GameGuiActiveAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData);
@@ -39,5 +38,6 @@ void GameGuiCalculateSlowScore(void);
void GameGuiShowScore(void);
void GameGuiDrawUnboardingSequence(TYPE_PLAYER* ptrPlayer);
void GameGuiAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData);
+bool GameGuiFinishedDialog(TYPE_PLAYER* ptrPlayer);
#endif //__GAME_GUI_HEADER__
diff --git a/Source/MainMenuBtnAni.c b/Source/MainMenuBtnAni.c
index 8f92672..fd01220 100644
--- a/Source/MainMenuBtnAni.c
+++ b/Source/MainMenuBtnAni.c
@@ -73,3 +73,5 @@ short MainMenuBtnAni[] =
1,
0
};
+
+size_t MainMenuBtnAni_sz = sizeof(MainMenuBtnAni) / sizeof(MainMenuBtnAni[0]);
diff --git a/Source/MainMenuBtnAni.h b/Source/MainMenuBtnAni.h
index 7741bb4..bd27b75 100644
--- a/Source/MainMenuBtnAni.h
+++ b/Source/MainMenuBtnAni.h
@@ -12,8 +12,6 @@
* Defines
* *************************************/
-#define MAIN_MENU_BTN_ANI_SIZE 53
-
/* *************************************
* Global prototypes
* *************************************/
@@ -23,5 +21,6 @@
* *************************************/
extern short MainMenuBtnAni[];
+extern size_t MainMenuBtnAni_sz;
#endif // __MAINMENUBTN_HEADER__
diff --git a/Source/Makefile b/Source/Makefile
index 8d35664..befbc21 100644
--- a/Source/Makefile
+++ b/Source/Makefile
@@ -1,5 +1,6 @@
CC = psx-gcc
-DEFINE= -DFIXMATH_FAST_SIN -D_PAL_MODE_ -DPSXSDK_DEBUG
+DEFINE= -DFIXMATH_FAST_SIN -D_PAL_MODE_
+DEFINE += -DPSXSDK_DEBUG
DEFINE += -DNO_CDDA
DEFINE += -DNO_INTRO
LIBS= -lfixmath
diff --git a/Source/Menu.c b/Source/Menu.c
index 168ef00..d2d1122 100644
--- a/Source/Menu.c
+++ b/Source/Menu.c
@@ -432,7 +432,7 @@ void MainMenuDrawButton(TYPE_MMBtn * btn)
MenuSpr.w = BUTTON_SIZE;
MenuSpr.h = BUTTON_SIZE;
- if(btn->timer < MAIN_MENU_BTN_ANI_SIZE)
+ if(btn->timer < MainMenuBtnAni_sz)
{
btn->timer++;
}
diff --git a/Source/PltParser.c b/Source/PltParser.c
index 8b2cabe..f88964c 100644
--- a/Source/PltParser.c
+++ b/Source/PltParser.c
@@ -211,6 +211,7 @@ bool PltParserLoadFile(char * strPath, TYPE_FLIGHT_DATA * ptrFlightData)
case REMAINING_TIME_INDEX:
ptrFlightData->RemainingTime[aircraftIndex] = (uint8_t)atoi(lineBufferPtr);
+ dprintf("ptrFlightData->RemainingTime[%d] = %d\n", aircraftIndex, ptrFlightData->RemainingTime[aircraftIndex]);
break;
diff --git a/Source/System.c b/Source/System.c
index 5d7f4de..48533c1 100644
--- a/Source/System.c
+++ b/Source/System.c
@@ -213,38 +213,102 @@ void SystemIncreaseGlobalTimer(void)
global_timer++;
}
+/* *******************************************************************
+ *
+ * @name: uint64_t SystemGetGlobalTimer(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Returns internal global timer value.
+ *
+ * *******************************************************************/
+
uint64_t SystemGetGlobalTimer(void)
{
return global_timer;
}
+/* *******************************************************************
+ *
+ * @name: void SystemDisableScreenRefresh(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Resets VBlank IRQ flag.
+ *
+ * *******************************************************************/
+
void SystemDisableScreenRefresh(void)
{
refresh_needed = false;
}
+/* *******************************************************************
+ *
+ * @name: bool System1SecondTick(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: bool variable with a 1-cycle-length pulse that gets
+ * set each second.
+ *
+ * *******************************************************************/
+
bool System1SecondTick(void)
{
return one_second_timer;
}
+/* *******************************************************************
+ *
+ * @name: bool System100msTick(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: bool variable with a 1-cycle-length pulse that gets
+ * set every 100 milliseconds.
+ *
+ * *******************************************************************/
+
bool System100msTick(void)
{
return hundred_ms_timer;
}
+/* *******************************************************************
+ *
+ * @name bool System500msTick(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: bool variable with a 1-cycle-length pulse that gets
+ * set every 500 milliseconds.
+ *
+ * *******************************************************************/
+
bool System500msTick(void)
{
return five_hundred_ms_timer;
}
-static uint64_t last_one_second_tick;
- static uint64_t last_100_ms_tick;
- static uint64_t last_500_ms_tick;
+/* *******************************************************************
+ *
+ * @name void SystemRunTimers(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: general timer handler
+ *
+ * @remarks: 1 second, 500 ms and 100 ms ticks get updated here.
+ *
+ * *******************************************************************/
void SystemRunTimers(void)
{
-
+ static uint64_t last_one_second_tick;
+ static uint64_t last_100_ms_tick;
+ static uint64_t last_500_ms_tick;
+
SystemCheckTimer(&one_second_timer, &last_one_second_tick, REFRESH_FREQUENCY);
#ifdef _PAL_MODE_
@@ -256,6 +320,16 @@ void SystemRunTimers(void)
}
+/* ********************************************************************************
+ *
+ * @name void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Checks if needed time step has been elapsed. If true, flag gets set.
+ *
+ * *******************************************************************************/
+
void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step)
{
if(*timer == true)
@@ -270,6 +344,19 @@ void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step)
}
}
+/* ****************************************************************************************
+ *
+ * @name bool SystemLoadFileToBuffer(char * fname, uint8_t* buffer, uint32_t szBuffer)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Given an input path, it fills a buffer pointed to by "buffer" with
+ * maximum size "szBuffer" with data from CD-ROM.
+ *
+ * @return: true if file has been loaded successfully, false otherwise.
+ *
+ * ****************************************************************************************/
+
bool SystemLoadFileToBuffer(char * fname, uint8_t* buffer, uint32_t szBuffer)
{
FILE *f;
@@ -325,16 +412,48 @@ bool SystemLoadFileToBuffer(char * fname, uint8_t* buffer, uint32_t szBuffer)
return true;
}
+/* ****************************************************************************************
+ *
+ * @name bool SystemLoadFile(char *fname)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Given an input file name, it loads its conents into internal buffer.
+ *
+ * @return: true if file has been loaded successfully, false otherwise.
+ *
+ * ****************************************************************************************/
+
bool SystemLoadFile(char *fname)
{
return SystemLoadFileToBuffer(fname,file_buffer,sizeof(file_buffer));
}
+/* ******************************************************************
+ *
+ * @name uint8_t* SystemGetBufferAddress(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: Reportedly, returns internal buffer initial address.
+ *
+ * *****************************************************************/
+
uint8_t* SystemGetBufferAddress(void)
{
return file_buffer;
}
+/* ******************************************************************
+ *
+ * @name void SystemWaitCycles(uint32_t cycles)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: halts program execution for n-"cycles"
+ *
+ * *****************************************************************/
+
void SystemWaitCycles(uint32_t cycles)
{
uint64_t currentTime = global_timer;
@@ -342,26 +461,83 @@ void SystemWaitCycles(uint32_t cycles)
while(global_timer < (currentTime + cycles) );
}
+/* ******************************************************************
+ *
+ * @name uint32_t SystemRand(uint32_t min, uint32_t max)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: random number between "min" and "max".
+ *
+ * @remarks: rand seed must be set before using this function, or
+ * you will predictable values otherwise!
+ *
+ * *****************************************************************/
+
uint32_t SystemRand(uint32_t min, uint32_t max)
{
return rand() % (max - min + 1) + min;
}
+/* ***********************************************************************
+ *
+ * @name void SystemSetEmergencyMode(bool value)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Sets emergency mode flag.
+ *
+ * @remarks: emergency mode is set once that a controller is unplugged.
+ *
+ * ***********************************************************************/
+
void SystemSetEmergencyMode(bool value)
{
emergency_mode = value;
}
+/* ***********************************************************************
+ *
+ * @name bool SystemGetEmergencyMode(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: returns emergency mode flag.
+ *
+ * ***********************************************************************/
+
bool SystemGetEmergencyMode(void)
{
return emergency_mode;
}
+/* ***********************************************************************
+ *
+ * @name volatile bool SystemIsBusy(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @return: returns system busy flag.
+ *
+ * ***********************************************************************/
+
volatile bool SystemIsBusy(void)
{
return system_busy;
}
+/* ****************************************************************************
+ *
+ * @name bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: checks if a certain value is contained in a buffer with size "sz".
+ *
+ * @return: true if value is contained inside buffer, false otherwise.
+ *
+ * ****************************************************************************/
+
bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz)
{
size_t i = 0;
@@ -377,6 +553,19 @@ bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz)
return false;
}
+/* ****************************************************************************
+ *
+ * @name bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: checks if a certain value is contained in a buffer with size "sz".
+ * Variant for u16 variables.
+ *
+ * @return: true if value is contained inside buffer, false otherwise.
+ *
+ * ****************************************************************************/
+
bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz)
{
size_t i = 0;
@@ -392,6 +581,25 @@ 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;
@@ -426,20 +634,38 @@ TYPE_TIMER* SystemCreateTimer(uint32_t t, bool rf, void (*timer_callback)(void)
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++)
{
- timer_array[i].Timeout_Callback = NULL;
- timer_array[i].busy = false;
- timer_array[i].repeat_flag = false;
- timer_array[i].time = 0;
- timer_array[i].orig_time = 0;
+ 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;
@@ -473,6 +699,18 @@ void SystemUserTimersHandler(void)
}
}
+/* *********************************************************************
+ *
+ * @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;