aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-08-09 22:51:15 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-08-09 22:51:15 +0200
commitb807ee7ca59c13bbc698595da5e56eb6dd6daa2f (patch)
treefac7fe6970f8c341aaae4d3b6224e8469210c38e
parent8700a329d07bae49228f10b50999a161a235d140 (diff)
* Added some comments on Game.c.
* Some performance optimizations on Game.c (removed unneeded "for" loops). * Timer 2 is now handler (ISR still not working). * SYSTEM.CNF: EVENT parameter increased to 7.
-rw-r--r--Levels/LEVEL1.PLT14
-rw-r--r--Source/Game.c197
-rw-r--r--Source/Makefile35
-rw-r--r--Source/System.c38
-rw-r--r--cdimg/DATA/LEVELS/LEVEL1.PLT14
-rw-r--r--cdimg/SYSTEM.CNF2
6 files changed, 230 insertions, 70 deletions
diff --git a/Levels/LEVEL1.PLT b/Levels/LEVEL1.PLT
index ef29b6e..51f4ca5 100644
--- a/Levels/LEVEL1.PLT
+++ b/Levels/LEVEL1.PLT
@@ -11,9 +11,19 @@ ARRIVAL;PHX2015;100;00:10;0;360
ARRIVAL;PHX2016;100;00:40;0;360
ARRIVAL;PHX2017;100;00:50;0;360
ARRIVAL;PHX2018;100;01:40;0;360
-ARRIVAL;PHX2018;100;01:20;0;360
-ARRIVAL;PHX2018;100;02:00;0;360
+ARRIVAL;PHX2019;100;01:20;0;360
+ARRIVAL;PHX2020;100;02:00;0;360
+ARRIVAL;PHX2021;100;00:05;0;360
+ARRIVAL;PHX2022;100;00:15;0;360
+ARRIVAL;PHX2023;100;00:45;0;360
+ARRIVAL;PHX2024;100;01:45;0;360
+ARRIVAL;PHX2025;100;01:20;0;360
+ARRIVAL;PHX2026;100;01:10;0;360
DEPARTURE;PHX1000;100;00:05;19;180
+DEPARTURE;PHX1001;100;00:15;19;180
+DEPARTURE;PHX1002;100;00:30;19;180
+DEPARTURE;PHX1003;100;00:45;19;180
+DEPARTURE;PHX1004;100;01:10;19;180
DEPARTURE;PHX1280;100;01:30;19;180
DEPARTURE;PHX1332;100;00:50;21;180
DEPARTURE;PHX1333;100;01:00;19;180
diff --git a/Source/Game.c b/Source/Game.c
index 7626598..fdf9f8a 100644
--- a/Source/Game.c
+++ b/Source/Game.c
@@ -1077,6 +1077,26 @@ char* GetGameLevelTitle(void)
return GameLevelTitle;
}
+/* ******************************************************************************************
+ *
+ * @name: void GameAircraftState(uint8_t i)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * TYPE_PLAYER* ptrPlayer:
+ * Pointer to a player structure
+ *
+ *
+ * @brief:
+ * Draws all tiles depending on GameLevelBuffer configuration.
+ *
+ * @remarks:
+ * Tiles are usually rendered with normal RGB values unless parking/runway is busy
+ * or ptrPlayer->InvalidPath == true.
+ *
+ * ******************************************************************************************/
+
void GameAircraftState(uint8_t i)
{
uint16_t target[2] = {0};
@@ -1166,6 +1186,26 @@ void GameAircraftState(uint8_t i)
}
}
+/* ******************************************************************************************
+ *
+ * @name: void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * TYPE_PLAYER* ptrPlayer:
+ * Pointer to a player structure
+ *
+ *
+ * @brief:
+ * Draws all tiles depending on GameLevelBuffer configuration.
+ *
+ * @remarks:
+ * Tiles are usually rendered with normal RGB values unless parking/runway is busy
+ * or ptrPlayer->InvalidPath == true.
+ *
+ * ******************************************************************************************/
+
void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
{
uint16_t i;
@@ -1173,7 +1213,7 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
uint8_t columns = 0;
uint8_t rows = 0;
bool flip_id;
- bool used_rwy;
+ bool used_rwy = SystemContains_u16(ptrPlayer->RwyArray[0], GameUsedRwy, GAME_MAX_RUNWAYS);
uint8_t aux_id;
GsSprite * ptrTileset;
const uint8_t rwy_sine_step = 24;
@@ -1181,11 +1221,14 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
static bool rwy_sine_decrease = false;
TYPE_ISOMETRIC_POS tileIsoPos;
TYPE_CARTESIAN_POS tileCartPos;
+
+ uint16_t init_timer_value = 0;
+ uint16_t end_timer_value = 0;
// Prepare runway to be painted in blue if player is on runway selection mode
if(ptrPlayer->SelectRunway == true)
{
- GameGetSelectedRunwayArray(GameRwy[ptrPlayer->SelectedRunway], ptrPlayer->RwyArray, sizeof(ptrPlayer->RwyArray));
+
/*Serial_printf("Runway array:\n");
for(j = 0; j < GAME_MAX_RWY_LENGTH; j++)
@@ -1312,8 +1355,6 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
{
continue;
}
-
- used_rwy = false;
ptrTileset->r = NORMAL_LUMINANCE;
ptrTileset->g = NORMAL_LUMINANCE;
@@ -1325,17 +1366,6 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
&&
(SystemContains_u16(i, ptrPlayer->RwyArray, GAME_MAX_RWY_LENGTH) == true) )
{
- for(j = 0; j < GAME_MAX_RUNWAYS; j++)
- {
- if(GameUsedRwy[j] != 0)
- {
- if(SystemContains_u16(GameUsedRwy[j], ptrPlayer->RwyArray, GAME_MAX_RWY_LENGTH) == true)
- {
- used_rwy = true;
- break;
- }
- }
- }
if(used_rwy == true)
{
@@ -1382,32 +1412,11 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
(CurrentTile == TILE_RWY_HOLDING_POINT_2) ) )
{
bool bHoldingRwyBusy = false;
-
- for(j = 0; j < FlightData.nAircraft; j++)
- {
- uint16_t* targets = AircraftGetTargets(j);
- uint16_t aircraftTile = AircraftGetTileFromFlightDataIndex(j);
- uint16_t lastTarget = 0;
- uint8_t k;
- for(k = 0; k < AIRCRAFT_MAX_TARGETS; k++)
- {
- if(targets[k] == 0)
- {
- break;
- }
+ init_timer_value = GetRCnt(2);
- lastTarget = targets[k];
- }
- if( (i == aircraftTile)
- ||
- (i == lastTarget) )
- {
- bHoldingRwyBusy = true;
- break;
- }
- }
+ end_timer_value = GetRCnt(2);
if(bHoldingRwyBusy == true)
{
@@ -1484,14 +1493,55 @@ void GameRenderLevel(TYPE_PLAYER* ptrPlayer)
ptrTileset->attribute &= ~(H_FLIP);
}
}
+
+ dprintf("GameRenderLevel execution time = %d\t"
+ "end_timer_value = 0x%04X\tinit_timer_value = 0x%04X\n",
+ end_timer_value - init_timer_value,
+ end_timer_value,
+ init_timer_value );
}
+/* *******************************************************************
+ *
+ * @name: void GameSetTime(uint8_t hour, uint8_t minutes)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief:
+ * Reportedly, it sets game time to specified hour and minutes.
+ *
+ *
+ * @remarks:
+ * To be used on GameInit() after PLT file parsing.
+ *
+ * *******************************************************************/
+
void GameSetTime(uint8_t hour, uint8_t minutes)
{
GameHour = hour;
GameMinutes = minutes;
}
+/* *******************************************************************
+ *
+ * @name: void GameActiveAircraft(uint8_t i)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * uint8_t i:
+ * Index from FlightData array.
+ *
+ * @brief:
+ * On each game cycle, FlightData.ActiveAircraft is set to 0 and
+ * number of active aircraft is recalculated.
+ *
+ * @remarks:
+ * Called ciclically from GameCalculations(). This function is
+ * executed GAME_MAX_AIRCRAFT times on each cycle.
+ *
+ * *******************************************************************/
+
void GameActiveAircraft(uint8_t i)
{
// Reset iterator when i == 0.
@@ -1507,6 +1557,29 @@ void GameActiveAircraft(uint8_t i)
}
}
+/* ******************************************************************************************
+ *
+ * @name: void GameStateShowAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * TYPE_PLAYER* ptrPlayer:
+ * Pointer to a player structure
+ *
+ * TYPE_FLIGH_DATA* ptrFlightData:
+ * In the end, pointer to FlightData data table, which contains
+ * information about all available flights.
+ *
+ * @brief:
+ * Handles ptrPlayer->ShowAircraftData state.
+ *
+ *
+ * @remarks:
+ * Called ciclically from GamePlayerHandler().
+ *
+ * ******************************************************************************************/
+
void GameStateShowAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
{
if(ptrPlayer->ShowAircraftData == true)
@@ -1527,6 +1600,29 @@ void GameStateShowAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightDa
}
}
+/* ******************************************************************************************
+ *
+ * @name: void GameStateLockTarget(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * TYPE_PLAYER* ptrPlayer:
+ * Pointer to a player structure
+ *
+ * TYPE_FLIGH_DATA* ptrFlightData:
+ * In the end, pointer to FlightData data table, which contains
+ * information about all available flights.
+ *
+ * @brief:
+ * Handles ptrPlayer->LockTarget state.
+ *
+ *
+ * @remarks:
+ * Called ciclically from GamePlayerHandler().
+ *
+ ******************************************************************************************/
+
void GameStateLockTarget(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
{
uint8_t AircraftIdx = ptrPlayer->FlightDataSelectedAircraft;
@@ -1572,6 +1668,29 @@ void GameStateLockTarget(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData
}
}
+/* ******************************************************************************************
+ *
+ * @name: void GameStateSelectTaxiwayRunway(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @param:
+ * TYPE_PLAYER* ptrPlayer:
+ * Pointer to a player structure
+ *
+ * TYPE_FLIGH_DATA* ptrFlightData:
+ * In the end, pointer to FlightData data table, which contains
+ * information about all available flights.
+ *
+ * @brief:
+ * Handler for ptrPlayer->SelectTaxiwayRunway.
+ *
+ *
+ * @remarks:
+ * Called ciclically from GamePlayerHandler().
+ *
+ * ******************************************************************************************/
+
void GameStateSelectTaxiwayRunway(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
{
TYPE_ISOMETRIC_POS IsoPos = CameraGetIsoPos(ptrPlayer);
@@ -1757,6 +1876,8 @@ void GameStateSelectRunway(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightDa
// Under this mode, always reset locking target.
ptrPlayer->LockTarget = false;
ptrPlayer->LockedAircraft = FLIGHT_DATA_INVALID_IDX;
+
+ GameGetSelectedRunwayArray(GameRwy[ptrPlayer->SelectedRunway], ptrPlayer->RwyArray, sizeof(ptrPlayer->RwyArray));
CameraMoveToIsoPos(ptrPlayer, IsoPos);
diff --git a/Source/Makefile b/Source/Makefile
index 1567492..dfe4290 100644
--- a/Source/Makefile
+++ b/Source/Makefile
@@ -39,13 +39,9 @@ OBJECTS = $(addprefix $(OBJ_DIR)/,main.o System.o Menu.o Gfx.o Pad.o MainMenuBtn
DEPS = $(OBJECTS:.o=.d)
-all: levels image
+build: levels $(PROJECT).bin
-rebuild: clean all
-
-build: $(PROJECT).exe
-
-objects: $(OBJECTS)
+rebuild: clean build
-include $(DEPS)
@@ -57,24 +53,27 @@ clean:
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d
$(CC) $< -o $@ $(DEFINE) $(CC_FLAGS) -MMD
-$(PROJECT).elf: objects
+$(PROJECT).elf: $(OBJECTS)
$(LINKER) Obj/*.o -o Exe/$(PROJECT).elf $(LIBS) -Wl,--gc-sections
-
-$(PROJECT).exe: $(PROJECT).elf
- $(ELF2EXE) Exe/$(PROJECT).elf Exe/$(PROJECT).exe $(ELF2EXE_FLAGS)
- cp Exe/$(PROJECT).exe ../cdimg
-
-image: build
- rm -f $(PROJECT).iso $(PROJECT).bin
- rm -f $(PROJECT).cue
+
+$(PROJECT).iso: $(PROJECT).exe
+# rm -f $@
mkisofs -o $(PROJECT).iso -V $(PROJECT) -sysid PLAYSTATION ../cdimg
+
+$(PROJECT).bin: $(PROJECT).iso
+ rm -f $@
+ rm -f $(PROJECT).cue
mkpsxiso $(PROJECT).iso $(PROJECT).bin $(LICENSE_FILE) $(MUSIC_TRACKS)
- mv $(PROJECT).bin ../Bin
+# $(PROJECT).cue is automatically generated by mkpsxiso
+ rm -f $^
+ mv $@ ../Bin
mv $(PROJECT).cue ../Bin
- rm -f $(PROJECT).cue
- rm -f $(PROJECT).iso
$(GNU_SIZE) Exe/$(PROJECT).elf
+$(PROJECT).exe: $(PROJECT).elf
+ $(ELF2EXE) Exe/$(PROJECT).elf Exe/$(PROJECT).exe $(ELF2EXE_FLAGS)
+ cp Exe/$(PROJECT).exe ../cdimg
+
emulator:
export PATH=$$PATH:$(EMULATOR_DIR)
$(EMULATOR) -cdfile $(PROJECT_DIR)/Bin/$(PROJECT).bin $(EMULATOR_FLAGS)
diff --git a/Source/System.c b/Source/System.c
index 2a527ae..6444b37 100644
--- a/Source/System.c
+++ b/Source/System.c
@@ -27,6 +27,7 @@
static void SystemCheckTimer(bool* timer, uint64_t* last_timer, uint8_t step);
static void SystemSetStackPattern(void);
+static void ISR_RootCounter2(void);
/* *************************************
* Local Variables
@@ -117,13 +118,26 @@ void SystemInit(void)
SystemSetStackPattern();
- SetRCnt(RCntCNT2,0xFFFF,RCntSC);
- StartRCnt(RCntCNT2);
+ //SetRCntHandler(&ISR_RootCounter2, 2, 0xA560);
+
+ Serial_printf("Begin SetRCntHandler\n");
+ SetRCntHandler(&ISR_RootCounter2, 2, 0xFFFF);
+ Serial_printf("End SetRCntHandler\n");
+
+ SystemEnableRCnt2Interrupt();
+}
+
+static volatile uint16_t u16_0_01seconds_cnt;
+
+void ISR_RootCounter2(void)
+{
+ Serial_printf("YO\n");
+ u16_0_01seconds_cnt++;
}
/* *******************************************************************
*
- * @name: void SystemInit(void)
+ * @name: void SystemSetRandSeed(void)
*
* @author: Xavier Del Campo
*
@@ -1178,8 +1192,8 @@ void SystemDevMenu(void)
DEVMENU_PAD2_RAW_DATA_TEXT_X = DEVMENU_PAD2_ID_TEXT_X,
DEVMENU_PAD2_RAW_DATA_TEXT_Y = DEVMENU_PAD2_ID_TEXT_Y + DEVMENU_TEXT_GAP,
- DEVMENU_ROOTCNT0_TEXT_X = DEVMENU_PAD2_RAW_DATA_TEXT_X,
- DEVMENU_ROOTCNT0_TEXT_Y = DEVMENU_PAD2_RAW_DATA_TEXT_Y + DEVMENU_TEXT_GAP,
+ DEVMENU_ROOTCNT2_TEXT_X = DEVMENU_PAD2_RAW_DATA_TEXT_X,
+ DEVMENU_ROOTCNT2_TEXT_Y = DEVMENU_PAD2_RAW_DATA_TEXT_Y + DEVMENU_TEXT_GAP,
};
if(devmenu_flag == true)
@@ -1243,10 +1257,16 @@ void SystemDevMenu(void)
"Pad2 raw data = 0x%04X",
PadTwoGetRawData() );
+ /*FontPrintText( &SmallFont,
+ DEVMENU_ROOTCNT2_TEXT_X,
+ DEVMENU_ROOTCNT2_TEXT_Y,
+ "Timer2 = 0x%04X",
+ GetRCnt(2) );*/
+
FontPrintText( &SmallFont,
- DEVMENU_ROOTCNT0_TEXT_X,
- DEVMENU_ROOTCNT0_TEXT_Y,
- "Timer0 = 0x%04X",
- (uint16_t)((*(uint32_t*)0x1F801100) & 0x00FF) );
+ DEVMENU_ROOTCNT2_TEXT_X,
+ DEVMENU_ROOTCNT2_TEXT_Y,
+ "Timer2 = 0x%04X, timer2 = 0x%04X",
+ u16_0_01seconds_cnt, GetRCnt(2) );
}
}
diff --git a/cdimg/DATA/LEVELS/LEVEL1.PLT b/cdimg/DATA/LEVELS/LEVEL1.PLT
index ef29b6e..51f4ca5 100644
--- a/cdimg/DATA/LEVELS/LEVEL1.PLT
+++ b/cdimg/DATA/LEVELS/LEVEL1.PLT
@@ -11,9 +11,19 @@ ARRIVAL;PHX2015;100;00:10;0;360
ARRIVAL;PHX2016;100;00:40;0;360
ARRIVAL;PHX2017;100;00:50;0;360
ARRIVAL;PHX2018;100;01:40;0;360
-ARRIVAL;PHX2018;100;01:20;0;360
-ARRIVAL;PHX2018;100;02:00;0;360
+ARRIVAL;PHX2019;100;01:20;0;360
+ARRIVAL;PHX2020;100;02:00;0;360
+ARRIVAL;PHX2021;100;00:05;0;360
+ARRIVAL;PHX2022;100;00:15;0;360
+ARRIVAL;PHX2023;100;00:45;0;360
+ARRIVAL;PHX2024;100;01:45;0;360
+ARRIVAL;PHX2025;100;01:20;0;360
+ARRIVAL;PHX2026;100;01:10;0;360
DEPARTURE;PHX1000;100;00:05;19;180
+DEPARTURE;PHX1001;100;00:15;19;180
+DEPARTURE;PHX1002;100;00:30;19;180
+DEPARTURE;PHX1003;100;00:45;19;180
+DEPARTURE;PHX1004;100;01:10;19;180
DEPARTURE;PHX1280;100;01:30;19;180
DEPARTURE;PHX1332;100;00:50;21;180
DEPARTURE;PHX1333;100;01:00;19;180
diff --git a/cdimg/SYSTEM.CNF b/cdimg/SYSTEM.CNF
index 6046a93..c803e3e 100644
--- a/cdimg/SYSTEM.CNF
+++ b/cdimg/SYSTEM.CNF
@@ -1,4 +1,4 @@
BOOT = cdrom:\AIRPORT.EXE;1
TCB = 4
-EVENT = 6
+EVENT = 7
STACK = 801FF800