diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2018-11-25 12:32:16 +0100 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2018-11-25 12:32:16 +0100 |
| commit | 135a1e93cb9b3a859c4269a94ababe33b3558f9a (patch) | |
| tree | d32c9b295895128b98f1af14e0c1d08a1da2b6f0 | |
| parent | e4ab93f21e73dd86c41c754f4401f87f58c80afe (diff) | |
* LEVEL3.PLT was incorrectly using Windows CRLF end of line.
* When assigning a parking slot, busy parking slots cannot be selected. Some work TODO yet, though.
| -rw-r--r-- | Bin/AIRPORT.bin | bin | 1698144 -> 1733424 bytes | |||
| -rw-r--r-- | Levels/LEVEL3.PLT | 18 | ||||
| -rw-r--r-- | Source/Aircraft.c | 11 | ||||
| -rw-r--r-- | Source/Aircraft.h | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | Source/Exe/AIRPORT.elf | bin | 348088 -> 485576 bytes | |||
| -rw-r--r-- | Source/Exe/AIRPORT.iso | bin | 1478656 -> 1509376 bytes | |||
| -rw-r--r-- | Source/Game.c | 206 | ||||
| -rw-r--r-- | Source/Game.h | 2 | ||||
| -rw-r--r-- | Source/GameStructures.h | 8 | ||||
| -rw-r--r-- | Source/Makefile | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | Source/MapEditor/tileset.ini | 0 | ||||
| -rw-r--r-- | Source/Pad.c | 4 | ||||
| -rw-r--r-- | Source/Pad.h | 2 | ||||
| -rw-r--r-- | Source/System.c | 606 | ||||
| -rw-r--r-- | Source/System.h | 4 | ||||
| -rw-r--r-- | Source/Timer.c | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Debug/MapEditor | bin | 1621888 -> 1621888 bytes | |||
| -rw-r--r--[-rwxr-xr-x] | Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Release/MapEditor | bin | 86944 -> 86944 bytes | |||
| -rw-r--r-- | cdimg/DATA/LEVELS/LEVEL3.PLT | 18 |
19 files changed, 488 insertions, 415 deletions
diff --git a/Bin/AIRPORT.bin b/Bin/AIRPORT.bin Binary files differindex 174d7e7..beb0632 100644 --- a/Bin/AIRPORT.bin +++ b/Bin/AIRPORT.bin diff --git a/Levels/LEVEL3.PLT b/Levels/LEVEL3.PLT index b15dbde..99efea3 100644 --- a/Levels/LEVEL3.PLT +++ b/Levels/LEVEL3.PLT @@ -6,12 +6,12 @@ #For example: 14:55 #Aircraft arrival (or departure) must be set relative to initial time, in HH:MM format. -ARRIVAL;PHX1802;100;00:10;0;360 -ARRIVAL;PHX1805;125;00:10;0;360 -ARRIVAL;PHX1806;125;00:30;0;360 -ARRIVAL;PHX1807;125;00:50;0;360 -ARRIVAL;PHX1808;125;01:30;0;360 -DEPARTURE;PHX1000;53;00:05;152;360 -DEPARTURE;PHX1001;53;00:15;153;360 -DEPARTURE;PHX1002;53;00:30;154;360 -DEPARTURE;PHX1003;53;00:45;155;360 +ARRIVAL;PHX1802;100;00:10;0;60 +ARRIVAL;PHX1805;125;00:10;0;60 +ARRIVAL;PHX1806;125;00:30;0;60 +ARRIVAL;PHX1807;125;00:50;0;60 +ARRIVAL;PHX1808;125;01:30;0;60 +DEPARTURE;PHX1000;53;00:05;152;120 +DEPARTURE;PHX1001;53;00:15;153;120 +DEPARTURE;PHX1002;53;00:30;154;120 +DEPARTURE;PHX1003;53;00:45;155;120 diff --git a/Source/Aircraft.c b/Source/Aircraft.c index 211f57e..b4c527c 100644 --- a/Source/Aircraft.c +++ b/Source/Aircraft.c @@ -55,7 +55,6 @@ static GsSprite UpDownArrowSpr; static GsSprite LeftRightArrowSpr;
static TYPE_ISOMETRIC_POS AircraftCenterIsoPos;
static TYPE_CARTESIAN_POS AircraftCenterPos;
-static char* AircraftLiveryNamesTable[] = {"PHX", NULL};
static AIRCRAFT_LIVERY AircraftLiveryTable[] = {AIRCRAFT_LIVERY_0, AIRCRAFT_LIVERY_UNKNOWN};
// Used to quickly link FlightData indexes against AircraftData indexes.
@@ -245,6 +244,12 @@ bool AircraftAddNew( TYPE_FLIGHT_DATA* const ptrFlightData, static AIRCRAFT_LIVERY AircraftLiveryFromFlightNumber(char* strFlightNumber)
{
+ static const char* const AircraftLiveryNamesTable[] =
+ {
+ "PHX",
+ NULL
+ };
+
int32_t liveryIndex;
char strLivery[4];
@@ -811,7 +816,7 @@ TYPE_ISOMETRIC_POS AircraftGetIsoPos(const uint8_t FlightDataIdx) return retIsoPos;
}
-void AircraftAddTargets(TYPE_AIRCRAFT_DATA* const ptrAircraft, uint16_t* targets)
+void AircraftAddTargets(TYPE_AIRCRAFT_DATA* const ptrAircraft, const uint16_t* const targets)
{
memcpy(ptrAircraft->Target, targets, sizeof (uint16_t) * AIRCRAFT_MAX_TARGETS);
ptrAircraft->TargetIdx = 0;
@@ -851,7 +856,7 @@ TYPE_AIRCRAFT_DATA* AircraftFromFlightDataIndex(const uint8_t index) return NULL;
}
-void AircraftFromFlightDataIndexAddTargets(uint8_t index, uint16_t* targets)
+void AircraftFromFlightDataIndexAddTargets(const uint8_t index, const uint16_t* const targets)
{
TYPE_AIRCRAFT_DATA* const ptrAircraft = AircraftFromFlightDataIndex(index);
diff --git a/Source/Aircraft.h b/Source/Aircraft.h index 239ec4c..f1d02b7 100644 --- a/Source/Aircraft.h +++ b/Source/Aircraft.h @@ -16,8 +16,8 @@ void AircraftInit(void); void AircraftHandler(void);
void AircraftRender(TYPE_PLAYER* const ptrPlayer, uint8_t aircraftIdx);
TYPE_AIRCRAFT_DATA* AircraftFromFlightDataIndex(uint8_t index);
-void AircraftFromFlightDataIndexAddTargets(uint8_t index, uint16_t* targets);
-void AircraftAddTargets(TYPE_AIRCRAFT_DATA* const ptrAircraft, uint16_t* targets);
+void AircraftFromFlightDataIndexAddTargets(const uint8_t index, const uint16_t* const targets);
+void AircraftAddTargets(TYPE_AIRCRAFT_DATA* const ptrAircraft, const uint16_t* const targets);
TYPE_ISOMETRIC_POS AircraftGetIsoPos(const uint8_t FlightDataIdx);
uint16_t AircraftGetTileFromFlightDataIndex(const uint8_t index);
bool AircraftRemove(uint8_t aircraftIdx);
diff --git a/Source/Exe/AIRPORT.elf b/Source/Exe/AIRPORT.elf Binary files differindex 1a64341..19c91f2 100755..100644 --- a/Source/Exe/AIRPORT.elf +++ b/Source/Exe/AIRPORT.elf diff --git a/Source/Exe/AIRPORT.iso b/Source/Exe/AIRPORT.iso Binary files differindex 7516b99..f6006af 100644 --- a/Source/Exe/AIRPORT.iso +++ b/Source/Exe/AIRPORT.iso diff --git a/Source/Game.c b/Source/Game.c index 26bfb21..85918f7 100644 --- a/Source/Game.c +++ b/Source/Game.c @@ -245,7 +245,27 @@ static SsVag TakeoffSnd; static SsVag BeepSnd; // Instances for player-specific data -static TYPE_PLAYER PlayerData[MAX_PLAYERS]; +static TYPE_PLAYER PlayerData[MAX_PLAYERS] = +{ + [PLAYER_ONE] = + { + .PadKeyPressed_Callback = &PadOneKeyPressed, + .PadKeyReleased_Callback = &PadOneKeyReleased, + .PadKeySinglePress_Callback = &PadOneKeySinglePress, + .PadDirectionKeyPressed_Callback = &PadOneDirectionKeyPressed, + .PadLastKeySinglePressed_Callback = &PadOneGetLastKeySinglePressed + }, + + [PLAYER_TWO] = + { + .PadKeyPressed_Callback = &PadTwoKeyPressed, + .PadKeyReleased_Callback = &PadTwoKeyReleased, + .PadDirectionKeyPressed_Callback = &PadTwoDirectionKeyPressed, + .PadKeySinglePress_Callback = &PadTwoKeySinglePress, + .PadLastKeySinglePressed_Callback = &PadTwoGetLastKeySinglePressed + } + +}; static void* GamePltDest[] = {(TYPE_FLIGHT_DATA*)&FlightData }; @@ -434,7 +454,6 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) }; uint8_t i; - uint32_t track; static bool loaded; GameStartupFlag = true; @@ -452,7 +471,7 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) LoadMenu( &pGameCfg->PLTPath, GamePltDest, sizeof (char), - sizeof (GamePltDest) / sizeof (GamePltDest[0]) ); + ARRAY_SIZE(GamePltDest)); GameLoadLevel(pGameCfg->LVLPath); @@ -465,11 +484,6 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) memset(GameUsedRwy, 0, GAME_MAX_RUNWAYS * sizeof (uint16_t) ); PlayerData[PLAYER_ONE].Active = true; - PlayerData[PLAYER_ONE].PadKeyPressed_Callback = &PadOneKeyPressed; - PlayerData[PLAYER_ONE].PadKeyReleased_Callback = &PadOneKeyReleased; - PlayerData[PLAYER_ONE].PadKeySinglePress_Callback = &PadOneKeySinglePress; - PlayerData[PLAYER_ONE].PadDirectionKeyPressed_Callback = &PadOneDirectionKeyPressed; - PlayerData[PLAYER_ONE].PadLastKeySinglePressed_Callback = &PadOneGetLastKeySinglePressed; PlayerData[PLAYER_ONE].FlightDataPage = 0; PlayerData[PLAYER_ONE].UnboardingSequenceIdx = 0; @@ -488,12 +502,7 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) if (PlayerData[PLAYER_TWO].Active) { - PlayerData[PLAYER_TWO].PadKeyPressed_Callback = &PadTwoKeyPressed; - PlayerData[PLAYER_TWO].PadKeyReleased_Callback = &PadTwoKeyReleased; - PlayerData[PLAYER_TWO].PadDirectionKeyPressed_Callback = &PadTwoDirectionKeyPressed; PlayerData[PLAYER_TWO].FlightDataPage = 0; - PlayerData[PLAYER_TWO].PadKeySinglePress_Callback = &PadTwoKeySinglePress; - PlayerData[PLAYER_TWO].PadLastKeySinglePressed_Callback = &PadTwoGetLastKeySinglePressed; PlayerData[PLAYER_TWO].UnboardingSequenceIdx = 0; PlayerData[PLAYER_TWO].ShowAircraftData = false; @@ -553,7 +562,10 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) GameMouseSpr.g = NORMAL_LUMINANCE; GameMouseSpr.b = NORMAL_LUMINANCE; - GameSpawnMinTime = TimerCreate(GAME_MINIMUM_PARKING_SPAWN_TIME, false, &GameMinimumSpawnTimeout); + if (GameSpawnMinTime != NULL) + { + GameSpawnMinTime = TimerCreate(GAME_MINIMUM_PARKING_SPAWN_TIME, false, &GameMinimumSpawnTimeout); + } spawnMinTimeFlag = false; @@ -573,9 +585,11 @@ void GameInit(const TYPE_GAME_CONFIGURATION* const pGameCfg) GfxSetGlobalLuminance(0); - track = SystemRand(GAMEPLAY_FIRST_TRACK, GAMEPLAY_LAST_TRACK); + { + const uint32_t track = SystemRand(GAMEPLAY_FIRST_TRACK, GAMEPLAY_LAST_TRACK); - SfxPlayTrack(track); + SfxPlayTrack(track); + } } /* *************************************************************************************** @@ -732,20 +746,10 @@ void GameEmergencyMode(void) { uint8_t i; uint8_t disconnected_players = 0x00; - bool (*PadXConnected[MAX_PLAYERS])(void) = { [PLAYER_ONE] = &PadOneConnected, - [PLAYER_TWO] = &PadTwoConnected }; - - enum + static bool (*const PadXConnected[MAX_PLAYERS])(void) = { - ERROR_RECT_X = 32, - ERROR_RECT_W = X_SCREEN_RESOLUTION - (ERROR_RECT_X << 1), - - ERROR_RECT_Y = 16, - ERROR_RECT_H = Y_SCREEN_RESOLUTION - (ERROR_RECT_Y << 1), - - ERROR_RECT_R = 0, - ERROR_RECT_G = 32, - ERROR_RECT_B = NORMAL_LUMINANCE + [PLAYER_ONE] = &PadOneConnected, + [PLAYER_TWO] = &PadTwoConnected }; enum @@ -759,21 +763,37 @@ void GameEmergencyMode(void) { bool enabled = false; - GsRectangle errorRct = {.x = ERROR_RECT_X, - .w = ERROR_RECT_W, - .y = ERROR_RECT_Y, - .h = ERROR_RECT_H, - .r = ERROR_RECT_R, - .g = ERROR_RECT_G, - .b = ERROR_RECT_B }; - if (SystemGetEmergencyMode()) { + enum + { + ERROR_RECT_X = 32, + ERROR_RECT_W = X_SCREEN_RESOLUTION - (ERROR_RECT_X << 1), + + ERROR_RECT_Y = 16, + ERROR_RECT_H = Y_SCREEN_RESOLUTION - (ERROR_RECT_Y << 1), + + ERROR_RECT_R = 0, + ERROR_RECT_G = 32, + ERROR_RECT_B = NORMAL_LUMINANCE + }; + + static const GsRectangle errorRct = + { + .x = ERROR_RECT_X, + .w = ERROR_RECT_W, + .y = ERROR_RECT_Y, + .h = ERROR_RECT_H, + .r = ERROR_RECT_R, + .g = ERROR_RECT_G, + .b = ERROR_RECT_B + }; + // One of the pads has been disconnected during gameplay // Show an error screen until it is disconnected again. GsSortCls(0,0,0); - GsSortRectangle(&errorRct); + GsSortRectangle((GsRectangle*)&errorRct); for (i = 0; i < MAX_PLAYERS; i++) { @@ -1466,12 +1486,6 @@ static void GameLoadLevel(const char* path) static void GameAircraftState(const uint8_t i) { - uint16_t target[2] = {0}; - // Arrays are copied to AircraftAddNew, so we create a first and only - // target which is the parking tile itself, and the second element - // is just the NULL character. - // Not an ideal solution, but the best one currently available. - if (FlightData.Finished[i] == false) { if ((FlightData.Hours[i] == 0) @@ -1515,6 +1529,12 @@ static void GameAircraftState(const uint8_t i) if (bParkingBusy == false) { + uint16_t target[2] = {0}; + // Arrays are copied to AircraftAddNew, so we create a first and only + // target which is the parking tile itself, and the second element + // is just the NULL character. + // Not an ideal solution, but the best one currently available. + FlightData.State[i] = STATE_PARKED; aircraftCreated = true; @@ -1535,12 +1555,12 @@ static void GameAircraftState(const uint8_t i) } else if (FlightData.FlightDirection[i] == ARRIVAL) { + const uint32_t idx = SystemRand(SOUND_M1_INDEX, ARRAY_SIZE(ApproachSnds)); + Serial_printf("Flight %d set to STATE_APPROACH.\n", i); FlightData.State[i] = STATE_APPROACH; aircraftCreated = true; - const uint32_t idx = SystemRand(SOUND_M1_INDEX, ARRAY_SIZE(ApproachSnds)); - // Play chatter sound. SfxPlaySound(&ApproachSnds[idx]); @@ -1727,9 +1747,38 @@ static void GameRenderTerrainPrecalculations(TYPE_PLAYER* const ptrPlayer, const || (CurrentTile == TILE_PARKING_2) ) ) { - tileData->r = NORMAL_LUMINANCE >> 2; - tileData->g = rwy_sine; - tileData->b = NORMAL_LUMINANCE >> 2; + bool parkingBusy = false; + + uint8_t aircraftIndex; + + for (aircraftIndex = 0; aircraftIndex < GAME_MAX_AIRCRAFT; aircraftIndex++) + { + const TYPE_AIRCRAFT_DATA* const ptrAircraft = AircraftFromFlightDataIndex(aircraftIndex); + + if (ptrAircraft->State == STATE_PARKED) + { + const uint16_t tile = AircraftGetTileFromFlightDataIndex(aircraftIndex); + + if (i == tile) + { + parkingBusy = true; + break; + } + } + } + + if (parkingBusy) + { + tileData->r = rwy_sine; + tileData->g = NORMAL_LUMINANCE >> 2; + tileData->b = NORMAL_LUMINANCE >> 2; + } + else + { + tileData->r = NORMAL_LUMINANCE >> 2; + tileData->g = rwy_sine; + tileData->b = NORMAL_LUMINANCE >> 2; + } } } else if (ptrPlayer->ShowAircraftData) @@ -2050,7 +2099,6 @@ static void GameStateLockTarget(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* static void GameStateSelectTaxiwayRunway(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* const ptrFlightData) { - TYPE_ISOMETRIC_POS IsoPos = CameraGetIsoPos(ptrPlayer); uint8_t i; uint16_t target_tile; @@ -2062,8 +2110,6 @@ static void GameStateSelectTaxiwayRunway(TYPE_PLAYER* const ptrPlayer, TYPE_FLIG ptrPlayer->LockTarget = false; ptrPlayer->LockedAircraft = FLIGHT_DATA_INVALID_IDX; - ptrPlayer->SelectedTile = GameGetTileFromIsoPosition(&IsoPos); - if (GamePathToTile(ptrPlayer, ptrFlightData) == false) { ptrPlayer->InvalidPath = true; @@ -2159,7 +2205,6 @@ static void GameStateSelectTaxiwayRunway(TYPE_PLAYER* const ptrPlayer, TYPE_FLIG * **************************************************************************************************/ static void GameStateSelectTaxiwayParking(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* const ptrFlightData) { - TYPE_ISOMETRIC_POS IsoPos = CameraGetIsoPos(ptrPlayer); uint8_t i; uint16_t target_tile; @@ -2169,13 +2214,37 @@ static void GameStateSelectTaxiwayParking(TYPE_PLAYER* const ptrPlayer, TYPE_FLI ptrPlayer->LockTarget = false; ptrPlayer->LockedAircraft = FLIGHT_DATA_INVALID_IDX; - ptrPlayer->SelectedTile = GameGetTileFromIsoPosition(&IsoPos); - if (GamePathToTile(ptrPlayer, ptrFlightData) == false) { ptrPlayer->InvalidPath = true; } +#if 0 + for (i = 0; GAME_MAX_AIRCRAFT; i++) + { + if (ptrPlayer->InvalidPath == false) + { + const TYPE_AIRCRAFT_DATA* const ptrAircraft = AircraftFromFlightDataIndex(i); + + if (ptrAircraft != NULL) + { + if (ptrAircraft->State == STATE_PARKED) + { + const uint16_t tile = AircraftGetTileFromFlightDataIndex(i); + + if (ptrPlayer->SelectedTile == tile) + { + ptrPlayer->InvalidPath = true; + break; + } + } + } + } + } +#endif + + Serial_printf("Yo\n"); + if (ptrPlayer->PadKeySinglePress_Callback(PAD_TRIANGLE)) { // State exit. @@ -2201,13 +2270,6 @@ static void GameStateSelectTaxiwayParking(TYPE_PLAYER* const ptrPlayer, TYPE_FLI target_tile = levelBuffer[ptrPlayer->Waypoints[ptrPlayer->LastWaypointIdx]] & ~(TILE_MIRROR_FLAG); - Serial_printf("ptrPlayer->LastWaypointIdx = %d\n", - ptrPlayer->LastWaypointIdx); - - Serial_printf("target_tile = %d, TILE_PARKING = %d\n", - target_tile, - TILE_PARKING); - SfxPlaySound(&BeepSnd); if ( (target_tile == TILE_PARKING) @@ -2287,7 +2349,6 @@ static void GameStateSelectRunway(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA } else if (ptrPlayer->PadKeySinglePress_Callback(PAD_CROSS)) { - ptrPlayer->SelectRunway = false; bool success = false; if (SystemContains_u16(GameRwy[ptrPlayer->SelectedRunway], GameUsedRwy, GAME_MAX_RUNWAYS) == false) @@ -2725,10 +2786,13 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* // TODO: Algorithm is not correct. If TILE_RWY_EXIT is placed further, // but returns a match earlier than other rwyExitTiles[], invalid targets // are returned to aircraft. We should check this before proceeding. - uint8_t rwyExitTiles[] = { TILE_RWY_EXIT, - TILE_RWY_EXIT | TILE_MIRROR_FLAG, - TILE_RWY_EXIT_2, - TILE_RWY_EXIT_2 | TILE_MIRROR_FLAG }; + static const uint8_t rwyExitTiles[] = + { + TILE_RWY_EXIT, + TILE_RWY_EXIT | TILE_MIRROR_FLAG, + TILE_RWY_EXIT_2, + TILE_RWY_EXIT_2 | TILE_MIRROR_FLAG + }; ptrFlightData->State[aircraftIndex] = STATE_FINAL; GameScore += SCORE_REWARD_FINAL; @@ -2742,7 +2806,7 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* for (i = 0; (i < GAME_MAX_RWY_LENGTH) && (rwyExit == 0); i++) { - for (j = 0; j < (sizeof (rwyExitTiles) / sizeof (rwyExitTiles[0])); j++) + for (j = 0; j < ARRAY_SIZE(rwyExitTiles); j++) { if (rwyTiles[i] == rwyExitTiles[j]) { @@ -2995,7 +3059,7 @@ FL_STATE GameTargetsReached(uint16_t firstTarget, uint8_t index) * * ****************************************************************************/ -uint16_t GameGetTileFromIsoPosition(TYPE_ISOMETRIC_POS* IsoPos) +uint16_t GameGetTileFromIsoPosition(const TYPE_ISOMETRIC_POS* const IsoPos) { uint16_t tile; @@ -3194,6 +3258,10 @@ bool GamePathToTile(TYPE_PLAYER* const ptrPlayer, TYPE_FLIGHT_DATA* const ptrFli uint16_t y_diff; uint16_t temp_tile; + const TYPE_ISOMETRIC_POS IsoPos = CameraGetIsoPos(ptrPlayer); + + ptrPlayer->SelectedTile = GameGetTileFromIsoPosition(&IsoPos); + if (ptrPlayer->SelectedTile == GAME_INVALID_TILE_SELECTION) { return false; diff --git a/Source/Game.h b/Source/Game.h index 44ade47..8e25753 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -47,7 +47,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(const TYPE_ISOMETRIC_POS* const IsoPos); FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx); uint32_t GameGetScore(void); bool GameInsideLevelFromIsoPos(TYPE_ISOMETRIC_FIX16_POS* ptrIsoPos); diff --git a/Source/GameStructures.h b/Source/GameStructures.h index 1eff166..7d271ed 100644 --- a/Source/GameStructures.h +++ b/Source/GameStructures.h @@ -214,10 +214,10 @@ typedef struct uint16_t NextAircraftTime;
// Pad callbacks.
- bool (*PadKeyPressed_Callback)(unsigned short);
- bool (*PadKeyReleased_Callback)(unsigned short);
- bool (*PadKeySinglePress_Callback)(unsigned short);
- bool (*PadDirectionKeyPressed_Callback)(void);
+ bool (*const PadKeyPressed_Callback)(unsigned short);
+ bool (*const PadKeyReleased_Callback)(unsigned short);
+ bool (*const PadKeySinglePress_Callback)(unsigned short);
+ bool (*const PadDirectionKeyPressed_Callback)(void);
unsigned short (*PadLastKeySinglePressed_Callback)(void);
}TYPE_PLAYER;
diff --git a/Source/Makefile b/Source/Makefile index 5596d79..9e3ff2a 100644 --- a/Source/Makefile +++ b/Source/Makefile @@ -11,7 +11,7 @@ GNU_SIZE = mipsel-unknown-elf-size # Custom define flags for GCC DEFINE= -DFIXMATH_FAST_SIN -D_PAL_MODE_ -#DEFINE += -DPSXSDK_DEBUG +DEFINE += -DPSXSDK_DEBUG DEFINE += -DNO_CDDA DEFINE += -DNO_INTRO @@ -27,7 +27,7 @@ CDROM_ROOT=$(PROJECT_DIR)/cdimg BIN_TARGET_PATH = $(PROJECT_DIR)/Bin #Uncomment this DEFINE below to use Airport together with OpenSend + QPSXSerial toolchain. -#DEFINE += -DSERIAL_INTERFACE +DEFINE += -DSERIAL_INTERFACE # PSXSDK tools definitions # ELF2EXE: @@ -124,7 +124,7 @@ SPRITE_OBJECTS += $(addprefix $(OBJ_FONTS_PATH)/, INTROFNT.TIM \ # Instructions # ------------------------------------ -$(BIN_TARGET_PATH)/$(PROJECT).bin: $(EXE_PATH)/$(PROJECT).iso $(MUSIC_TRACKS) +$(BIN_TARGET_PATH)/$(PROJECT).bin: $(EXE_PATH)/$(PROJECT).iso #~ mkpsxiso $< $@ $(LICENSE_FILE) -s $(addprefix --track=, $(MUSIC_TRACKS)) mkpsxiso $< $@ $(LICENSE_FILE) -s # $(PROJECT).cue is automatically generated by mkpsxiso diff --git a/Source/MapEditor/tileset.ini b/Source/MapEditor/tileset.ini index 488e023..488e023 100755..100644 --- a/Source/MapEditor/tileset.ini +++ b/Source/MapEditor/tileset.ini diff --git a/Source/Pad.c b/Source/Pad.c index 0af5007..a506414 100644 --- a/Source/Pad.c +++ b/Source/Pad.c @@ -95,7 +95,7 @@ static unsigned short pad2_cheat_array[CHEAT_ARRAY_SIZE]; static TYPE_TIMER* pad1_cheat_timer; static TYPE_TIMER* pad2_cheat_timer; -static TYPE_CHEAT * cheatsArray[PAD_MAX_CHEATS]; +static const TYPE_CHEAT* cheatsArray[PAD_MAX_CHEATS]; psx_pad_state PadOneGetState(void) { @@ -558,7 +558,7 @@ void PadCheatHandler(uint8_t n_pad) cheat_array[j] = key; } -bool PadAddCheat(TYPE_CHEAT * cheat) +bool PadAddCheat(const TYPE_CHEAT* const cheat) { static uint8_t idx = 0; diff --git a/Source/Pad.h b/Source/Pad.h index 8ef04eb..72d5dca 100644 --- a/Source/Pad.h +++ b/Source/Pad.h @@ -61,7 +61,7 @@ bool PadTwoIsVibrationEnabled(void); unsigned short PadOneGetRawData(void); unsigned short PadTwoGetRawData(void); -bool PadAddCheat(TYPE_CHEAT * cheat); +bool PadAddCheat(const TYPE_CHEAT* const cheat); unsigned short* PadGetPlayerOneCheatArray(void); diff --git a/Source/System.c b/Source/System.c index 1b35de6..44b6571 100644 --- a/Source/System.c +++ b/Source/System.c @@ -1,5 +1,5 @@ /* ************************************* - * Includes + * Includes * *************************************/ #include "System.h" #include "Pad.h" @@ -10,7 +10,7 @@ #include "Timer.h" /* ************************************* - * Defines + * Defines * *************************************/ #define FILE_BUFFER_SIZE (128 << 10) // 128 KB @@ -20,14 +20,14 @@ #define I_MASK (*(volatile unsigned int*)0x1F801074) /* ************************************* - * Local Prototypes + * Local Prototypes * *************************************/ static void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step); static void SystemSetStackPattern(void); static void ISR_RootCounter2(void); /* ************************************* - * Local Variables + * Local Variables * *************************************/ //Buffer to store any kind of files. It supports files up to 128 kB static uint8_t file_buffer[FILE_BUFFER_SIZE]; @@ -67,17 +67,17 @@ static unsigned char sine_counter; * *******************************************************************/ void SystemInit(void) { - enum - { - RCNT2_100US_TICK_COUNTER = 0xA560 - }; + enum + { + RCNT2_100US_TICK_COUNTER = 0xA560 + }; - //Reset global timer - global_timer = 0; - //Reset 1 second timer - one_second_timer = 0; + //Reset global timer + global_timer = 0; + //Reset 1 second timer + one_second_timer = 0; - //PSXSDK init + //PSXSDK init #ifdef SERIAL_INTERFACE // PSX_INIT_SAVESTATE | PSX_INIT_CD flags are not needed // when coming from OpenSend. @@ -86,46 +86,46 @@ void SystemInit(void) PSX_InitEx(PSX_INIT_SAVESTATE | PSX_INIT_CD); #endif // SERIAL_INTERFACE - //Graphics init - GsInit(); - //Clear VRAM - GsClearMem(); - //Set Video Resolution + //Graphics init + GsInit(); + //Clear VRAM + GsClearMem(); + //Set Video Resolution #ifdef _PAL_MODE_ - GsSetVideoMode(X_SCREEN_RESOLUTION, Y_SCREEN_RESOLUTION, VMODE_PAL); + GsSetVideoMode(X_SCREEN_RESOLUTION, Y_SCREEN_RESOLUTION, VMODE_PAL); #else - GsSetVideoMode(X_SCREEN_RESOLUTION, Y_SCREEN_RESOLUTION, VMODE_NTSC); + GsSetVideoMode(X_SCREEN_RESOLUTION, Y_SCREEN_RESOLUTION, VMODE_NTSC); #endif //_PAL_MODE_ - //SPU init - SsInit(); - //Reset all user-handled timers - TimerReset(); - //Pads init - PadInit(); - //Set Drawing Environment - GfxInitDrawEnv(); - //Set Display Environment - GfxInitDispEnv(); - //Set VBlank Handler for screen refresh - SetVBlankHandler(&ISR_SystemDefaultVBlank); - //Set Primitive List - GfxSetDefaultPrimitiveList(); - // Init memory card - MemCardInit(); - //Initial value for system_busy - system_busy = false; + //SPU init + SsInit(); + //Reset all user-handled timers + TimerReset(); + //Pads init + PadInit(); + //Set Drawing Environment + GfxInitDrawEnv(); + //Set Display Environment + GfxInitDispEnv(); + //Set VBlank Handler for screen refresh + SetVBlankHandler(&ISR_SystemDefaultVBlank); + //Set Primitive List + GfxSetDefaultPrimitiveList(); + // Init memory card + MemCardInit(); + //Initial value for system_busy + system_busy = false; //Development menu flag devmenu_flag = false; //Emergency mode flag emergency_mode = false; - GfxSetGlobalLuminance(NORMAL_LUMINANCE); + GfxSetGlobalLuminance(NORMAL_LUMINANCE); - SystemSetStackPattern(); + SystemSetStackPattern(); - // Configure root counter 2 so that ISR_RootCounter2 - // is executed every 100 us. - SetRCntHandler(&ISR_RootCounter2, 2, RCNT2_100US_TICK_COUNTER); + // Configure root counter 2 so that ISR_RootCounter2 + // is executed every 100 us. + SetRCntHandler(&ISR_RootCounter2, 2, RCNT2_100US_TICK_COUNTER); SystemEnableRCnt2Interrupt(); } @@ -139,7 +139,7 @@ static volatile uint16_t u16_0_01seconds_cnt_prev; * @author: Xavier Del Campo * * @brief: - * Executed on RCnt2 ISR every 100 us. + * Executed on RCnt2 ISR every 100 us. * * *******************************************************************/ void ISR_RootCounter2(void) @@ -148,9 +148,9 @@ void ISR_RootCounter2(void) if ((int16_t)(u16_0_01seconds_cnt - 1000) >= (int16_t)(u16_0_01seconds_cnt_prev)) { - u16_0_01seconds_cnt_prev = u16_0_01seconds_cnt; - //~ DEBUG_PRINT_VAR(u16_0_01seconds_cnt_prev); - } + u16_0_01seconds_cnt_prev = u16_0_01seconds_cnt; + //~ DEBUG_PRINT_VAR(u16_0_01seconds_cnt_prev); + } } /* ******************************************************************* @@ -160,24 +160,24 @@ void ISR_RootCounter2(void) * @author: Xavier Del Campo * * @brief: - * Calls srand() while avoiding multiple calls by setting internal - * variable rand_seed to true. Internal variable "global_timer" is - * used to generate the new seed. + * Calls srand() while avoiding multiple calls by setting internal + * variable rand_seed to true. Internal variable "global_timer" is + * used to generate the new seed. * * @remarks: - * It is recommended to call it once user has pressed any key. + * It is recommended to call it once user has pressed any key. * * *******************************************************************/ void SystemSetRandSeed(void) { - if (rand_seed == false) - { - rand_seed = true; - //Set random seed using global timer as reference - srand((unsigned int)global_timer); - - Serial_printf("Seed used: %d\n",(unsigned int)global_timer); - } + if (rand_seed == false) + { + rand_seed = true; + //Set random seed using global timer as reference + srand((unsigned int)global_timer ^ GetRCnt(2)); + + Serial_printf("Seed used: %d\n",(unsigned int)global_timer); + } } /* ******************************************************************* @@ -187,17 +187,17 @@ void SystemSetRandSeed(void) * @author: Xavier Del Campo * * @brief: - * Reportedly, returns whether rand seed has already been set. + * Reportedly, returns whether rand seed has already been set. * * @remarks: * * @return: - * Reportedly, returns whether rand seed has already been set. + * Reportedly, returns whether rand seed has already been set. * * *******************************************************************/ bool SystemIsRandSeedSet(void) { - return rand_seed; + return rand_seed; } /* ******************************************************************* @@ -211,12 +211,12 @@ bool SystemIsRandSeedSet(void) * @remarks: * * @return: - * Returns whether VSync flag has been enabled. + * Returns whether VSync flag has been enabled. * * *******************************************************************/ bool SystemRefreshNeeded(void) { - return refresh_needed; + return refresh_needed; } /* ******************************************************************* @@ -228,8 +228,8 @@ bool SystemRefreshNeeded(void) * @brief: * * @remarks: - * Called from VSync interrupt. Called 50 times a second in PAL mode, - * 60 times a second in NTSC mode. + * Called from VSync interrupt. Called 50 times a second in PAL mode, + * 60 times a second in NTSC mode. * * *******************************************************************/ void ISR_SystemDefaultVBlank(void) @@ -240,7 +240,7 @@ void ISR_SystemDefaultVBlank(void) temp_fps = 0; } - refresh_needed = true; + refresh_needed = true; } /* ******************************************************************* @@ -252,7 +252,7 @@ void ISR_SystemDefaultVBlank(void) * @brief: * * @remarks: - * Called by Game module in order to calculate frames per second. + * Called by Game module in order to calculate frames per second. * * *******************************************************************/ void SystemAcknowledgeFrame(void) @@ -271,7 +271,7 @@ void SystemAcknowledgeFrame(void) * stores its value into a variable. * * @remarks: - * To be called only once, preferibly on SystemCyclic(). + * To be called only once, preferibly on SystemCyclic(). * * *******************************************************************/ void SystemCalculateSine(void) @@ -282,7 +282,7 @@ void SystemCalculateSine(void) SINE_EFFECT_MAX = 240 }; - static bool sine_decrease = false; + static bool sine_decrease = false; if (sine_decrease == false) { @@ -331,15 +331,15 @@ unsigned char SystemGetSineValue(void) * @author: Xavier Del Campo * * @brief: - * Increases internal variable responsible for time handling. + * Increases internal variable responsible for time handling. * * @remarks: - * Usually called from ISR_SystemDefaultVBlank(). + * Usually called from ISR_SystemDefaultVBlank(). * * *******************************************************************/ void SystemIncreaseGlobalTimer(void) { - global_timer++; + global_timer++; } /* ******************************************************************* @@ -353,7 +353,7 @@ void SystemIncreaseGlobalTimer(void) * *******************************************************************/ volatile uint64_t SystemGetGlobalTimer(void) { - return global_timer; + return global_timer; } /* ******************************************************************* @@ -367,7 +367,7 @@ volatile uint64_t SystemGetGlobalTimer(void) * *******************************************************************/ void SystemDisableScreenRefresh(void) { - refresh_needed = false; + refresh_needed = false; } /* ******************************************************************* @@ -377,12 +377,12 @@ void SystemDisableScreenRefresh(void) * @author: Xavier Del Campo * * @return: bool variable with a 1-cycle-length pulse that gets - * set each second. + * set each second. * * *******************************************************************/ bool System1SecondTick(void) { - return one_second_timer; + return one_second_timer; } /* ******************************************************************* @@ -392,114 +392,114 @@ bool System1SecondTick(void) * @author: Xavier Del Campo * * @return: bool variable with a 1-cycle-length pulse that gets - * set every 100 milliseconds. + * set every 100 milliseconds. * * *******************************************************************/ bool System100msTick(void) { - return hundred_ms_timer; + return hundred_ms_timer; } /* ******************************************************************* * - * @name bool System500msTick(void) + * @name bool System500msTick(void) * * @author: Xavier Del Campo * * @return: bool variable with a 1-cycle-length pulse that gets - * set every 500 milliseconds. + * set every 500 milliseconds. * * *******************************************************************/ bool System500msTick(void) { - return five_hundred_ms_timer; + return five_hundred_ms_timer; } /* ******************************************************************* * - * @name void SystemRunTimers(void) + * @name void SystemRunTimers(void) * * @author: Xavier Del Campo * - * @brief: general timer handler + * @brief: general timer handler * - * @remarks: 1 second, 500 ms and 100 ms ticks get updated here. + * @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; + 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); + SystemCheckTimer(&one_second_timer, &last_one_second_tick, REFRESH_FREQUENCY); #ifdef _PAL_MODE_ - SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 2 /* 2 * 50 ms = 100 ms */); - SystemCheckTimer(&five_hundred_ms_timer, &last_500_ms_tick, 10 /* 10 * 50 ms = 500 ms */); + SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 2 /* 2 * 50 ms = 100 ms */); + SystemCheckTimer(&five_hundred_ms_timer, &last_500_ms_tick, 10 /* 10 * 50 ms = 500 ms */); #else // _PAL_MODE_ - SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 3); + SystemCheckTimer(&hundred_ms_timer, &last_100_ms_tick, 3); #endif // _PAL_MODE_ } /* ******************************************************************************** * - * @name void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step) + * @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. + * @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) - { - *timer = false; - } - - if (global_timer >= (*last_timer + step) ) - { - *timer = true; - *last_timer = global_timer; - } + if (*timer) + { + *timer = false; + } + + if (global_timer >= (*last_timer + step) ) + { + *timer = true; + *last_timer = global_timer; + } } /* **************************************************************************************** * - * @name bool SystemLoadFileToBuffer(char* fname, uint8_t* buffer, uint32_t szBuffer) + * @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. + * @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. + * @return: true if file has been loaded successfully, false otherwise. * * ****************************************************************************************/ bool SystemLoadFileToBuffer(const char* fname, uint8_t* buffer, uint32_t szBuffer) { #ifdef SERIAL_INTERFACE - uint8_t fileSizeBuffer[sizeof (uint32_t)] = {0}; + uint8_t fileSizeBuffer[sizeof (uint32_t)] = {0}; uint32_t i; #else // SERIAL_INTERFACE FILE *f; #endif // SERIAL_INTERFACE - int32_t size = 0; + int32_t size = 0; - // Wait for possible previous operation from the GPU before entering this section. - while ( (SystemIsBusy()) || (GfxIsGPUBusy()) ); + // Wait for possible previous operation from the GPU before entering this section. + while ( (SystemIsBusy()) || (GfxIsGPUBusy()) ); - SystemDisableRCnt2Interrupt(); + SystemDisableRCnt2Interrupt(); - if (fname == NULL) - { - Serial_printf("SystemLoadFile: NULL fname!\n"); - return false; - } + if (fname == NULL) + { + Serial_printf("SystemLoadFile: NULL fname!\n"); + return false; + } - memset(buffer,0,szBuffer); + memset(buffer,0,szBuffer); static char completeFileName[256]; @@ -546,29 +546,29 @@ bool SystemLoadFileToBuffer(const char* fname, uint8_t* buffer, uint32_t szBuffe f = fopen((char*)completeFileName, "r"); - if (f == NULL) - { - Serial_printf("SystemLoadFile: file could not be found!\n"); - //File couldn't be found - return false; - } + if (f == NULL) + { + Serial_printf("SystemLoadFile: file could not be found!\n"); + //File couldn't be found + return false; + } - fseek(f, 0, SEEK_END); + fseek(f, 0, SEEK_END); - size = ftell(f); + size = ftell(f); - if (size > szBuffer) - { - Serial_printf("SystemLoadFile: Exceeds file buffer size (%d bytes)\n",size); - //Bigger than 128 kB (buffer's max size) - return false; - } + if (size > szBuffer) + { + Serial_printf("SystemLoadFile: Exceeds file buffer size (%d bytes)\n",size); + //Bigger than 128 kB (buffer's max size) + return false; + } - fseek(f, 0, SEEK_SET); //f->pos = 0; + fseek(f, 0, SEEK_SET); //f->pos = 0; - fread(buffer, sizeof (char), size, f); + fread(buffer, sizeof (char), size, f); - fclose(f); + fclose(f); SystemEnableVBlankInterrupt(); SystemEnableRCnt2Interrupt(); @@ -577,65 +577,65 @@ bool SystemLoadFileToBuffer(const char* fname, uint8_t* buffer, uint32_t szBuffe #endif // SERIAL_INTERFACE - Serial_printf("File \"%s\" loaded successfully!\n",completeFileName); + Serial_printf("File \"%s\" loaded successfully!\n",completeFileName); - return true; + return true; } /* **************************************************************************************** * - * @name bool SystemLoadFile(char*fname) + * @name bool SystemLoadFile(char*fname) * * @author: Xavier Del Campo * - * @brief: Given an input file name, it loads its conents into internal buffer. + * @brief: Given an input file name, it loads its conents into internal buffer. * - * @return: true if file has been loaded successfully, false otherwise. + * @return: true if file has been loaded successfully, false otherwise. * * ****************************************************************************************/ bool SystemLoadFile(const char* fname) { - return SystemLoadFileToBuffer(fname,file_buffer,sizeof (file_buffer)); + return SystemLoadFileToBuffer(fname,file_buffer,sizeof (file_buffer)); } /* ****************************************************************** * - * @name uint8_t* SystemGetBufferAddress(void) + * @name uint8_t* SystemGetBufferAddress(void) * * @author: Xavier Del Campo * - * @return: Reportedly, returns internal buffer initial address. + * @return: Reportedly, returns internal buffer initial address. * * *****************************************************************/ uint8_t* SystemGetBufferAddress(void) { - return file_buffer; + return file_buffer; } /* ****************************************************************** * - * @name void SystemClearFileBuffer(void) + * @name void SystemClearFileBuffer(void) * * @author: Xavier Del Campo * - * @return: Fills internal buffer with zeros + * @return: Fills internal buffer with zeros * * *****************************************************************/ void SystemClearFileBuffer(void) { - memset(file_buffer, 0, sizeof (file_buffer)); + memset(file_buffer, 0, sizeof (file_buffer)); } /* ****************************************************************** * - * @name uint32_t SystemRand(uint32_t min, uint32_t max) + * @name uint32_t SystemRand(uint32_t min, uint32_t max) * * @author: Xavier Del Campo * - * @return: random number between "min" and "max". + * @return: random number between "min" and "max". * * @remarks: rand seed must be set before using this function, or - * you will predictable values otherwise! + * you will predictable values otherwise! * * *****************************************************************/ uint32_t SystemRand(uint32_t min, uint32_t max) @@ -645,272 +645,267 @@ uint32_t SystemRand(uint32_t min, uint32_t max) //~ Serial_printf("Warning: calling rand() before srand()\n"); } - return rand() % (max - min + 1) + min; + return rand() % (max - min + 1) + min; } /* *********************************************************************** * - * @name void SystemSetEmergencyMode(bool value) + * @name void SystemSetEmergencyMode(bool value) * * @author: Xavier Del Campo * - * @brief: Sets emergency mode flag. + * @brief: Sets emergency mode flag. * * @remarks: emergency mode is set once that a controller is unplugged. * * ***********************************************************************/ void SystemSetEmergencyMode(bool value) { - emergency_mode = value; + emergency_mode = value; } /* *********************************************************************** * - * @name bool SystemGetEmergencyMode(void) + * @name bool SystemGetEmergencyMode(void) * * @author: Xavier Del Campo * - * @return: returns emergency mode flag. + * @return: returns emergency mode flag. * * ***********************************************************************/ bool SystemGetEmergencyMode(void) { - return emergency_mode; + return emergency_mode; } /* *********************************************************************** * - * @name volatile bool SystemIsBusy(void) + * @name volatile bool SystemIsBusy(void) * * @author: Xavier Del Campo * - * @return: returns system busy flag. + * @return: returns system busy flag. * * ***********************************************************************/ volatile bool SystemIsBusy(void) { - return system_busy; + return system_busy; } /* **************************************************************************** * - * @name bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz) + * @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". + * @brief: checks if a certain value is contained in a buffer with size "sz". * - * @return: true if value is contained inside buffer, false otherwise. + * @return: true if value is contained inside buffer, false otherwise. * * ****************************************************************************/ bool SystemContains_u8(const uint8_t value, const uint8_t* const buffer, const size_t sz) { - size_t i = 0; + size_t i = 0; - for (i = 0; i < sz; i++) - { - if (buffer[i] == value) - { - return true; - } - } + for (i = 0; i < sz; i++) + { + if (buffer[i] == value) + { + return true; + } + } - return false; + return false; } /* **************************************************************************** * - * @name bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz) + * @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. + * @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. + * @return: true if value is contained inside buffer, false otherwise. * * ****************************************************************************/ bool SystemContains_u16(const uint16_t value, const uint16_t* const buffer, const size_t sz) { - size_t i = 0; + size_t i = 0; - for (i = 0; i < sz; i++) - { - if (buffer[i] == value) - { - return true; - } - } + for (i = 0; i < sz; i++) + { + if (buffer[i] == value) + { + return true; + } + } - return false; + return false; } /* **************************************************************************************** * - * @name bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz) + * @name bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz) * * @author: Xavier Del Campo * - * @brief: Reportedly, it compares two arrays "arr1" and "arr2", with size "sz". + * @brief: Reportedly, it compares two arrays "arr1" and "arr2", with size "sz". * * @return: true if they are equal, false otherwise. * * ****************************************************************************************/ -bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz) +bool SystemArrayCompare(const unsigned short* const arr1, const unsigned short* const arr2, const size_t sz) { - size_t i; + size_t i; - for (i = 0; i < sz; i++) - { - if (arr1[i] != arr2[i]) - { - return false; - } - } + for (i = 0; i < sz; i++) + { + if (arr1[i] != arr2[i]) + { + return false; + } + } - return true; + return true; } /* **************************************************************************************** * - * @name void SystemPrintStackPointerAddress(void) + * @name void SystemPrintStackPointerAddress(void) * * @author: Xavier Del Campo * - * @brief: Prints stack usage in percentage via dprintf calls. + * @brief: Prints stack usage in percentage via dprintf calls. * * ****************************************************************************************/ void SystemPrintStackPointerAddress(void) { #ifdef PSXSDK_DEBUG // Used to avoid unused variable warning - void* ptr = NULL; - fix16_t used_bytes = fix16_from_int((int)((void*)BEGIN_STACK_ADDRESS - (void*)&ptr)); - fix16_t stackPercent = fix16_sdiv(used_bytes,fix16_from_int((int)STACK_SIZE)); - - stackPercent = fix16_smul(stackPercent, fix16_from_int((int)100)); - - Serial_printf("stackPercent: %d\n", stackPercent); - - Serial_printf("Stack begin pointer: 0x%08X\n" - "Stack pointer address: 0x%08X\n" - "Used %d%% of stack size.\n" - "\tUsed bytes: %d\n", - (void*)BEGIN_STACK_ADDRESS, - (void*)&ptr, - fix16_to_int(stackPercent), - fix16_to_int(used_bytes) ); + void* ptr = NULL; + fix16_t used_bytes = fix16_from_int((int)((void*)BEGIN_STACK_ADDRESS - (void*)&ptr)); + fix16_t stackPercent = fix16_sdiv(used_bytes,fix16_from_int((int)STACK_SIZE)); + + stackPercent = fix16_smul(stackPercent, fix16_from_int((int)100)); + + Serial_printf("stackPercent: %d\n", stackPercent); + + Serial_printf("Stack begin pointer: 0x%08X\n" + "Stack pointer address: 0x%08X\n" + "Used %d%% of stack size.\n" + "\tUsed bytes: %d\n", + (void*)BEGIN_STACK_ADDRESS, + (void*)&ptr, + fix16_to_int(stackPercent), + fix16_to_int(used_bytes) ); #endif // PSXSDK_DEBUG } /* **************************************************************************************** * - * @name void SystemCheckStack(void) + * @name void SystemCheckStack(void) * * @author: Xavier Del Campo * - * @brief: Compares stack top with expected byte pattern. If does not match, a stack + * @brief: Compares stack top with expected byte pattern. If does not match, a stack * overflow has been caused, and application returns to a safe state. * * ****************************************************************************************/ void SystemCheckStack(void) { - uint32_t * ptrStack = BEGIN_STACK_ADDRESS; - uint32_t data; - - ptrStack -= STACK_SIZE; - data = (*ptrStack); + const uint32_t* const ptrStack = BEGIN_STACK_ADDRESS - STACK_SIZE; + const uint32_t data = *ptrStack; - if (data != END_STACK_PATTERN) - { - Serial_printf("Stack overflow?\n"); + if (data != END_STACK_PATTERN) + { + Serial_printf("Stack overflow?\n"); - while (1); - } + while (1); + } } /* **************************************************************************************** * - * @name void SystemSetStackPattern(void) + * @name void SystemSetStackPattern(void) * * @author: Xavier Del Campo * - * @brief: Sets a determined byte pattern on stack top to detect possible stack + * @brief: Sets a determined byte pattern on stack top to detect possible stack * overflow during execution. * * ****************************************************************************************/ void SystemSetStackPattern(void) { - uint32_t * ptrStack = BEGIN_STACK_ADDRESS; - - ptrStack -= STACK_SIZE; + uint32_t* const ptrStack = BEGIN_STACK_ADDRESS - STACK_SIZE; - *ptrStack = END_STACK_PATTERN; + *ptrStack = END_STACK_PATTERN; } /* **************************************************************************************** * - * @name int32_t SystemIndexOfStringArray(char* str, char** array) + * @name int32_t SystemIndexOfStringArray(char* str, char** array) * * @author: Xavier Del Campo * - * @brief: Finds string "str" inside an array of strings "array". + * @brief: Finds string "str" inside an array of strings "array". * * @return Index for a string "str" inside "array". -1 if it could not be found. * * ****************************************************************************************/ -int32_t SystemIndexOfStringArray(char* str, char** array) +int32_t SystemIndexOfStringArray(const char* str, const char* const* array) { - int32_t i; + int32_t i; - for (i = 0; array[i] != NULL; i++) - { - Serial_printf("String to find: %s\nEntry: %s\n", str, array[i]); + for (i = 0; array[i] != NULL; i++) + { + Serial_printf("String to find: %s\nEntry: %s\n", str, array[i]); - if (strcmp(str, array[i]) == 0) - { - Serial_printf("Match! Returning index %d...\n", i); - return i; - } - } + if (strcmp(str, array[i]) == 0) + { + Serial_printf("Match! Returning index %d...\n", i); + return i; + } + } - return -1; + return -1; } /* **************************************************************************************** * - * @name int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz) + * @name int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz) * * @author: Xavier Del Campo * - * @brief: For a uint16_t array, it returns index of a variable "value" inside an array. + * @brief: For a uint16_t array, it returns index of a variable "value" inside an array. * * @return Index for a variable "value" inside "array". -1 if it could not be found. * * ****************************************************************************************/ int32_t SystemIndexOf_U16(const uint16_t value, const uint16_t* const array, const uint32_t sz) { - int32_t i; + int32_t i; - for (i = 0; i < sz; i++) - { - if (value == array[i]) - { - return i; - } - } + for (i = 0; i < sz; i++) + { + if (value == array[i]) + { + return i; + } + } - return -1; + return -1; } /* **************************************************************************************** * - * @name int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz) + * @name int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz) * * @author: Xavier Del Campo * - * @brief: For a uint8_t array, it returns index of a variable "value" inside an array. + * @brief: For a uint8_t array, it returns index of a variable "value" inside an array. * "from" and "size_t" can be used to determine initial/ending positions. * * @return Index for a variable "value" inside "array". -1 if it could not be found. @@ -919,22 +914,22 @@ int32_t SystemIndexOf_U16(const uint16_t value, const uint16_t* const array, con int32_t SystemIndexOf_U8(const uint8_t value, const uint8_t* const array, const uint32_t from, const uint32_t sz) { - int32_t i; + int32_t i; - for (i = from; i < sz; i++) - { - if (value == array[i]) - { - return i; - } - } + for (i = from; i < sz; i++) + { + if (value == array[i]) + { + return i; + } + } - return -1; + return -1; } /* **************************************************************************************** * - * @name volatile uint8_t SystemGetFPS(void) + * @name volatile uint8_t SystemGetFPS(void) * * @author: Xavier Del Campo * @@ -948,11 +943,11 @@ volatile uint8_t SystemGetFPS(void) /* **************************************************************************************** * - * @name void SystemCyclicHandler(void) + * @name void SystemCyclicHandler(void) * * @author: Xavier Del Campo * - * @brief: It calls system handlers once an execution cycle has finished. + * @brief: It calls system handlers once an execution cycle has finished. * * * ****************************************************************************************/ @@ -962,26 +957,26 @@ void SystemCyclicHandler(void) SystemIncreaseGlobalTimer(); - SystemRunTimers(); + SystemRunTimers(); - TimerHandler(); + TimerHandler(); - SystemDisableScreenRefresh(); + SystemDisableScreenRefresh(); - MemCardHandler(); + MemCardHandler(); SystemCalculateSine(); - SystemCheckStack(); + SystemCheckStack(); } /* **************************************************************************************** * - * @name void SystemDisableVBlankInterrupt(void) + * @name void SystemDisableVBlankInterrupt(void) * * @author: Xavier Del Campo * - * @brief: Reportedly, this routine enables VBLANK interrupt flag. + * @brief: Reportedly, this routine enables VBLANK interrupt flag. * * @remark: Used when critical timing is needed or GPU activity is not desired * e.g.: when reading files from CD-ROM. @@ -989,31 +984,31 @@ void SystemCyclicHandler(void) * ****************************************************************************************/ void SystemDisableVBlankInterrupt(void) { - I_MASK &= ~(0x0001); + I_MASK &= ~(0x0001); } /* **************************************************************************************** * - * @name void SystemEnableVBlankInterrupt(void) + * @name void SystemEnableVBlankInterrupt(void) * * @author: Xavier Del Campo * - * @brief: Reportedly, this routine enables VBLANK interrupt flag. + * @brief: Reportedly, this routine enables VBLANK interrupt flag. * * * ****************************************************************************************/ void SystemEnableVBlankInterrupt(void) { - I_MASK |= (0x0001); + I_MASK |= (0x0001); } /* **************************************************************************************** * - * @name void SystemReturnToLoader(void) + * @name void SystemReturnToLoader(void) * * @author: Xavier Del Campo * - * @brief: Deinitializes PSXSDK library and returns to OpenSend loader, + * @brief: Deinitializes PSXSDK library and returns to OpenSend loader, * located at memory address 0x801A0000 * * ****************************************************************************************/ @@ -1030,11 +1025,11 @@ void SystemReturnToLoader(void) /* **************************************************************************************** * - * @name void SystemDevMenuToggle(void) + * @name void SystemDevMenuToggle(void) * * @author: Xavier Del Campo * - * @brief: It toggles a flag called "devmenu_flag" which, if true, shows information on + * @brief: It toggles a flag called "devmenu_flag" which, if true, shows information on * top of all drawn primitives for debugging/development purposes. * * ****************************************************************************************/ @@ -1045,11 +1040,11 @@ void SystemDevMenuToggle(void) /* **************************************************************************************** * - * @name void SystemEnableRCnt2Interrupt(void) + * @name void SystemEnableRCnt2Interrupt(void) * * @author: Xavier Del Campo * - * @brief: Enables bit 6 from I_MASK (0x1F801074)/IRQ6 RCNT2 (System clock / 8) + * @brief: Enables bit 6 from I_MASK (0x1F801074)/IRQ6 RCNT2 (System clock / 8) * * ****************************************************************************************/ void SystemEnableRCnt2Interrupt(void) @@ -1060,11 +1055,11 @@ void SystemEnableRCnt2Interrupt(void) /* **************************************************************************************** * - * @name void SystemDisableRCnt2Interrupt(void) + * @name void SystemDisableRCnt2Interrupt(void) * * @author: Xavier Del Campo * - * @brief: Disables bit 6 from I_MASK (0x1F801074)/IRQ6 RCNT2 (System clock / 8) + * @brief: Disables bit 6 from I_MASK (0x1F801074)/IRQ6 RCNT2 (System clock / 8) * * ****************************************************************************************/ void SystemDisableRCnt2Interrupt(void) @@ -1074,11 +1069,11 @@ void SystemDisableRCnt2Interrupt(void) /* **************************************************************************************** * - * @name void SystemDevMenu(void) + * @name void SystemDevMenu(void) * * @author: Xavier Del Campo * - * @brief: Shows information on top of all drawn primitives for debugging/development purposes. + * @brief: Shows information on top of all drawn primitives for debugging/development purposes. * * ****************************************************************************************/ void SystemDevMenu(void) @@ -1129,16 +1124,19 @@ void SystemDevMenu(void) if (devmenu_flag) { - GsRectangle devMenuBg = { .x = DEVMENU_BG_X, - .y = DEVMENU_BG_Y, - .w = DEVMENU_BG_W, - .h = DEVMENU_BG_H, - .r = DEVMENU_BG_R, - .g = DEVMENU_BG_G, - .b = DEVMENU_BG_B, - .attribute = ENABLE_TRANS | TRANS_MODE(0) }; - - GsSortRectangle(&devMenuBg); + static const GsRectangle devMenuBg = + { + .x = DEVMENU_BG_X, + .y = DEVMENU_BG_Y, + .w = DEVMENU_BG_W, + .h = DEVMENU_BG_H, + .r = DEVMENU_BG_R, + .g = DEVMENU_BG_G, + .b = DEVMENU_BG_B, + .attribute = ENABLE_TRANS | TRANS_MODE(0) + }; + + GsSortRectangle((GsRectangle*)&devMenuBg); FontPrintText( &SmallFont, DEVMENU_PAD1_STATUS_TEXT_X, diff --git a/Source/System.h b/Source/System.h index 90c1969..33a5758 100644 --- a/Source/System.h +++ b/Source/System.h @@ -81,7 +81,7 @@ bool SystemContains_u8(const uint8_t value, const uint8_t* const buffer, const s bool SystemContains_u16(const uint16_t value, const uint16_t* const buffer, const size_t sz); // Compares two arrays of unsigned short type. -bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz); +bool SystemArrayCompare(const unsigned short* const arr1, const unsigned short* const arr2, const size_t sz); // Prints stack pointer address using Serial_printf() void SystemPrintStackPointerAddress(void); @@ -92,7 +92,7 @@ void SystemCheckStack(void); // Looks for string "str" inside a string array pointed to by "array". // Returns index inside string array on success, -1 if not found. -int32_t SystemIndexOfStringArray(char* str, char** array); +int32_t SystemIndexOfStringArray(const char* str, const char* const* array); // Function overload for uint16_t data type. int32_t SystemIndexOf_U16(const uint16_t value, const uint16_t* array, const uint32_t sz); diff --git a/Source/Timer.c b/Source/Timer.c index 52030ea..a62723e 100644 --- a/Source/Timer.c +++ b/Source/Timer.c @@ -54,13 +54,15 @@ TYPE_TIMER* TimerCreate(uint32_t t, bool rf, void (*timer_callback)(void) ) for (i = 0; i < MAX_TIMERS; i++) { - if (timer_array[i].busy == false) + TYPE_TIMER* const ptrTimer = &timer_array[i]; + + if (ptrTimer->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; + ptrTimer->Timeout_Callback = timer_callback; + ptrTimer->time = t; + ptrTimer->orig_time = t; + ptrTimer->repeat_flag = rf; + ptrTimer->busy = true; success = true; break; } diff --git a/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Debug/MapEditor b/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Debug/MapEditor Binary files differindex aee24bb..aee24bb 100755..100644 --- a/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Debug/MapEditor +++ b/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Debug/MapEditor diff --git a/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Release/MapEditor b/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Release/MapEditor Binary files differindex 2156637..2156637 100755..100644 --- a/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Release/MapEditor +++ b/Source/build-MapEditor-Desktop_Qt_5_12_0_GCC_64bit-Release/MapEditor diff --git a/cdimg/DATA/LEVELS/LEVEL3.PLT b/cdimg/DATA/LEVELS/LEVEL3.PLT index b15dbde..99efea3 100644 --- a/cdimg/DATA/LEVELS/LEVEL3.PLT +++ b/cdimg/DATA/LEVELS/LEVEL3.PLT @@ -6,12 +6,12 @@ #For example: 14:55 #Aircraft arrival (or departure) must be set relative to initial time, in HH:MM format. -ARRIVAL;PHX1802;100;00:10;0;360 -ARRIVAL;PHX1805;125;00:10;0;360 -ARRIVAL;PHX1806;125;00:30;0;360 -ARRIVAL;PHX1807;125;00:50;0;360 -ARRIVAL;PHX1808;125;01:30;0;360 -DEPARTURE;PHX1000;53;00:05;152;360 -DEPARTURE;PHX1001;53;00:15;153;360 -DEPARTURE;PHX1002;53;00:30;154;360 -DEPARTURE;PHX1003;53;00:45;155;360 +ARRIVAL;PHX1802;100;00:10;0;60 +ARRIVAL;PHX1805;125;00:10;0;60 +ARRIVAL;PHX1806;125;00:30;0;60 +ARRIVAL;PHX1807;125;00:50;0;60 +ARRIVAL;PHX1808;125;01:30;0;60 +DEPARTURE;PHX1000;53;00:05;152;120 +DEPARTURE;PHX1001;53;00:15;153;120 +DEPARTURE;PHX1002;53;00:30;154;120 +DEPARTURE;PHX1003;53;00:45;155;120 |
