aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-07-27 07:41:25 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-07-27 07:41:25 +0200
commit153f078ec20cc442dd4dbe802dbd5fcb1748fcca (patch)
treedb82fe5fe9f6165b2239f3523d5f02ec8d9fa02b /Source
parentcb1c0345c766fada621b521ca39aac02ae25056b (diff)
downloadairport-153f078ec20cc442dd4dbe802dbd5fcb1748fcca.tar.gz
* Added comments on System.
* Files needed for Game are now only loaded once, except from LEVEL1.PLT. * Added DevMenu to get debug info. * ISR_LoadMenuVBlank() does not stop when accessing SIO. * On fopen() and SERIAL_INTERFACE defined, "#" is prepended and "@" is appended to filename string.
Diffstat (limited to 'Source')
-rw-r--r--Source/Game.c35
-rw-r--r--Source/GameGui.c17
-rw-r--r--Source/Gfx.c10
-rw-r--r--Source/LoadMenu.c15
-rw-r--r--Source/LoadMenu.h2
-rw-r--r--Source/Menu.c6
-rw-r--r--Source/Pad.c43
-rw-r--r--Source/Pad.h7
-rw-r--r--Source/PltParser.c2
-rw-r--r--Source/Serial.c9
-rw-r--r--Source/Serial.h1
-rw-r--r--Source/System.c292
-rw-r--r--Source/System.h6
13 files changed, 398 insertions, 47 deletions
diff --git a/Source/Game.c b/Source/Game.c
index 3679520..0dd932c 100644
--- a/Source/Game.c
+++ b/Source/Game.c
@@ -207,18 +207,19 @@ static uint8_t GameAircraftTilemap[GAME_MAX_MAP_SIZE][GAME_MAX_AIRCRAFT_PER_TILE
TYPE_PLAYER PlayerData[MAX_PLAYERS];
static char* GameFileList[] = { "cdrom:\\DATA\\SPRITES\\TILESET1.TIM;1" ,
- "cdrom:\\DATA\\LEVELS\\LEVEL1.PLT;1" ,
"cdrom:\\DATA\\SPRITES\\GAMEPLN.TIM;1" ,
"cdrom:\\DATA\\SPRITES\\PLNBLUE.CLT;1" ,
"cdrom:\\DATA\\SPRITES\\MOUSE.TIM;1" ,
"cdrom:\\DATA\\SPRITES\\BLDNGS1.TIM;1" };
-static void * GameFileDest[] = {(GsSprite*)&GameTilesetSpr ,
- (TYPE_FLIGHT_DATA*)&FlightData ,
+static void* GameFileDest[] = { (GsSprite*)&GameTilesetSpr ,
(GsSprite*)&GamePlaneSpr ,
- NULL ,
+ NULL,
(GsSprite*)&GameMouseSpr ,
(GsSprite*)&GameBuildingSpr };
+
+static char* GamePlt[] = { "cdrom:\\DATA\\LEVELS\\LEVEL1.PLT;1" };
+static void* GamePltDest[] = {(TYPE_FLIGHT_DATA*)&FlightData ,};
static char* GameLevelList[] = { "cdrom:\\DATA\\LEVELS\\LEVEL1.LVL;1"};
static uint16_t GameLevelBuffer[GAME_MAX_MAP_SIZE];
@@ -327,13 +328,24 @@ void GameInit(void)
{
uint8_t i;
uint32_t track;
+ static bool firstLoad = true;
GameStartupFlag = true;
-
- LoadMenu( GameFileList,
- GameFileDest,
- sizeof(GameFileList) / sizeof(char*),
- sizeof(GameFileDest) /sizeof(void*) );
+
+ if(firstLoad == true)
+ {
+ firstLoad = false;
+
+ LoadMenu( GameFileList,
+ GameFileDest,
+ sizeof(GameFileList) / sizeof(char*),
+ sizeof(GameFileDest) /sizeof(void*) );
+ }
+
+ LoadMenu( GamePlt,
+ GamePltDest,
+ sizeof(GamePlt) / sizeof(GamePlt[0]),
+ sizeof(GamePltDest) / sizeof(GamePltDest[0]) );
GameLoadLevel();
@@ -808,11 +820,10 @@ void GameGraphics(void)
if(split_screen == true)
{
- GfxSwapBuffers();
GfxDrawScene_NoSwap();
}
-
- GfxDrawScene();
+
+ GfxDrawScene();
}
void GameRenderBuildingAircraft(TYPE_PLAYER* ptrPlayer)
diff --git a/Source/GameGui.c b/Source/GameGui.c
index 4a00873..265f606 100644
--- a/Source/GameGui.c
+++ b/Source/GameGui.c
@@ -206,7 +206,7 @@ static char* GameFileList[] = { "cdrom:\\DATA\\SPRITES\\BUBBLE.TIM;1" ,
"cdrom:\\DATA\\SPRITES\\DEPARR.TIM;1" ,
"cdrom:\\DATA\\SPRITES\\PAGEUPDN.TIM;1" };
-static void * GameFileDest[] = {(GsSprite*)&BubbleSpr ,
+static void* GameFileDest[] = {(GsSprite*)&BubbleSpr ,
(TYPE_FONT*)&RadioFont ,
(GsSprite*)&DepArrSpr ,
(GsSprite*)&PageUpDownSpr };
@@ -243,10 +243,17 @@ void GameGuiInit(void)
RADIO_FONT_SPACING = 12
};
- LoadMenu( GameFileList,
- GameFileDest,
- sizeof(GameFileList) / sizeof(char*),
- sizeof(GameFileDest) /sizeof(void*) );
+ static bool firstLoad = true;
+
+ if(firstLoad == true)
+ {
+ firstLoad = false;
+
+ LoadMenu( GameFileList,
+ GameFileDest,
+ sizeof(GameFileList) / sizeof(char*),
+ sizeof(GameFileDest) /sizeof(void*) );
+ }
PauseRect.x[0] = PAUSE_DIALOG_X;
PauseRect.x[1] = PAUSE_DIALOG_X + PAUSE_DIALOG_W;
diff --git a/Source/Gfx.c b/Source/Gfx.c
index d9dd8ee..281f87b 100644
--- a/Source/Gfx.c
+++ b/Source/Gfx.c
@@ -95,9 +95,6 @@ static unsigned int prim_list[PRIMITIVE_LIST_SIZE];
static volatile bool gfx_busy;
// Dictates (R,G,B) brigthness to all sprites silently
static uint8_t global_lum;
-// When true, it draws a rectangle on top of all primitives with
-// information for development purposes.
-static bool GfxDevMenuEnableFlag;
static bool five_hundred_ms_show;
static bool one_second_show;
@@ -151,11 +148,6 @@ void GfxSwapBuffers(void)
}
}
-void GfxDevMenuEnable(void)
-{
- GfxDevMenuEnableFlag = true;
-}
-
void GfxInitDrawEnv(void)
{
@@ -183,6 +175,8 @@ void GfxSetPrimitiveList(void)
void GfxDrawScene_Fast(void)
{
+ SystemDevMenu();
+
if(System1SecondTick() == true)
{
one_second_show = one_second_show? false:true;
diff --git a/Source/LoadMenu.c b/Source/LoadMenu.c
index 878a416..4cd5ae7 100644
--- a/Source/LoadMenu.c
+++ b/Source/LoadMenu.c
@@ -73,7 +73,7 @@ static void LoadMenuInit(void);
static void ISR_LoadMenuVBlank(void);
static bool LoadMenuISRHasEnded(void);
static bool LoadMenuISRHasStarted(void);
-static void LoadMenuLoadFileList( char* fileList[], void * dest[],
+static void LoadMenuLoadFileList( char* fileList[], void* dest[],
uint8_t szFileList, uint8_t szDestList);
/* *************************************
@@ -90,7 +90,7 @@ static char* LoadMenuFiles[] = { "cdrom:\\DATA\\SPRITES\\PLANE.TIM;1",
"cdrom:\\DATA\\SPRITES\\LOADING.TIM;1",
"cdrom:\\DATA\\FONTS\\FONT_2.FNT;1" };
-static void * LoadMenuDest[] = {(GsSprite*)&LoadMenuPlaneSpr,
+static void* LoadMenuDest[] = {(GsSprite*)&LoadMenuPlaneSpr,
(GsSprite*)&LoadMenuTitleSpr,
(TYPE_FONT*)&SmallFont };
@@ -233,6 +233,8 @@ void LoadMenuInit(void)
SmallFont.spr.b = 0;
GfxSetGlobalLuminance(0);
+
+ Serial_printf("I_MASK = 0x%08X\n", (*(unsigned int*)0x1F801074));
SetVBlankHandler(&ISR_LoadMenuVBlank);
}
@@ -253,10 +255,9 @@ void ISR_LoadMenuVBlank(void)
{
uint8_t i;
- Serial_printf("SystemIsBusy() = %d\n", SystemIsBusy() );
- Serial_printf("GfxIsGPUBusy() = %d\n", GfxIsGPUBusy() );
+ SystemIncreaseGlobalTimer();
- if( (SystemIsBusy() == true) || (GfxIsGPUBusy() == true) )
+ if( (SystemIsBusy() == true) || (GfxIsGPUBusy() == true) || (SerialIsBusy() == true) )
{
return;
}
@@ -418,7 +419,7 @@ bool LoadMenuISRHasStarted(void)
}
void LoadMenu( char* fileList[],
- void * dest[],
+ void* dest[],
uint8_t szFileList , uint8_t szDestList)
{
@@ -433,7 +434,7 @@ void LoadMenu( char* fileList[],
}
-void LoadMenuLoadFileList( char* fileList[], void * dest[],
+void LoadMenuLoadFileList( char* fileList[], void* dest[],
uint8_t szFileList, uint8_t szDestList)
{
char aux_file_name[100];
diff --git a/Source/LoadMenu.h b/Source/LoadMenu.h
index 1fc1754..4605811 100644
--- a/Source/LoadMenu.h
+++ b/Source/LoadMenu.h
@@ -20,7 +20,7 @@
* *************************************/
void LoadMenu( char* fileList[],
- void * dest[],
+ void* dest[],
uint8_t szFileList , uint8_t szDestList);
void LoadMenuEnd(void);
diff --git a/Source/Menu.c b/Source/Menu.c
index ce54330..d07e06a 100644
--- a/Source/Menu.c
+++ b/Source/Menu.c
@@ -131,7 +131,7 @@ static char* MainMenuFiles[] = { "cdrom:\\DATA\\SPRITES\\MAINMENU.TIM;1" ,
#endif // NO_INTRO
};
-static void * MainMenuDest[] = { (GsSprite*)&MenuSpr ,
+static void* MainMenuDest[] = { (GsSprite*)&MenuSpr ,
(SsVag*)&BellSnd ,
(SsVag*)&AcceptSnd ,
(GsSprite*)&PsxDisk ,
@@ -250,7 +250,7 @@ void MainMenuInit(void)
PadAddCheat(&StackCheckCheat);
- DevMenuCheat.Callback = &GfxDevMenuEnable;
+ DevMenuCheat.Callback = &SystemDevMenuToggle;
memset(DevMenuCheat.Combination, 0 , CHEAT_ARRAY_SIZE);
memcpy( DevMenuCheat.Combination,
@@ -263,7 +263,7 @@ void MainMenuInit(void)
PadAddCheat(&DevMenuCheat);
- SerialCheat.Callback = (void*)0x801A0000;
+ SerialCheat.Callback = &SystemReturnToLoader;
memset(SerialCheat.Combination, 0 , CHEAT_ARRAY_SIZE);
memcpy( SerialCheat.Combination,
diff --git a/Source/Pad.c b/Source/Pad.c
index 6689020..9e892a6 100644
--- a/Source/Pad.c
+++ b/Source/Pad.c
@@ -100,11 +100,30 @@ psx_pad_state PadOneGetState(void)
{
psx_pad_state PadOne;
- PSX_PollPad_Fast(PAD_ONE,&PadOne);
+ PSX_PollPad_Fast(PAD_ONE, &PadOne);
return PadOne;
}
+unsigned char PadOneGetType(void)
+{
+ return PadOneGetState().type;
+}
+
+psx_pad_state PadTwoGetState(void)
+{
+ psx_pad_state PadTwo;
+
+ PSX_PollPad_Fast(PAD_TWO, &PadTwo);
+
+ return PadTwo;
+}
+
+unsigned char PadTwoGetType(void)
+{
+ return PadTwoGetState().type;
+}
+
bool PadOneConnected(void)
{
psx_pad_state PadOne = PadOneGetState();
@@ -117,6 +136,28 @@ bool PadOneConnected(void)
return true;
}
+bool PadTwoConnected(void)
+{
+ psx_pad_state PadTwo = PadTwoGetState();
+
+ if(PadTwo.status != PAD_STATUS_OK)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+unsigned char PadOneGetID(void)
+{
+ return PadOneGetState().id;
+}
+
+unsigned char PadTwoGetID(void)
+{
+ return PadTwoGetState().id;
+}
+
bool PadOneAnyKeyPressed(void)
{
return (bool)pad1;
diff --git a/Source/Pad.h b/Source/Pad.h
index 5b5fa1d..f88532f 100644
--- a/Source/Pad.h
+++ b/Source/Pad.h
@@ -23,6 +23,13 @@ void PadInit(void);
void PadClearData(void);
bool PadOneConnected(void);
+bool PadTwoConnected(void);
+
+unsigned char PadOneGetType(void);
+unsigned char PadTwoGetType(void);
+
+unsigned char PadOneGetID(void);
+unsigned char PadTwoGetID(void);
bool PadOneAnyKeyPressed(void);
bool PadTwoAnyKeyPressed(void);
diff --git a/Source/PltParser.c b/Source/PltParser.c
index a960059..eceb729 100644
--- a/Source/PltParser.c
+++ b/Source/PltParser.c
@@ -61,6 +61,8 @@ bool PltParserLoadFile(char* strPath, TYPE_FLIGHT_DATA* ptrFlightData)
}
strPltBuffer = SystemGetBufferAddress();
+
+ dprintf("%s\n", strPltBuffer);
PltParserResetBuffers(ptrFlightData);
diff --git a/Source/Serial.c b/Source/Serial.c
index 714581d..c7b085a 100644
--- a/Source/Serial.c
+++ b/Source/Serial.c
@@ -30,6 +30,7 @@ typedef enum
* *************************************/
static volatile SERIAL_STATE SerialState;
+static volatile bool serial_busy;
/* *************************************
* Local Prototypes
@@ -62,6 +63,7 @@ bool SerialRead(uint8_t* ptrArray, size_t nBytes)
bool SerialWrite(void* ptrArray, size_t nBytes)
{
+ serial_busy = true;
if(nBytes == 0)
{
@@ -79,9 +81,16 @@ bool SerialWrite(void* ptrArray, size_t nBytes)
}while(--nBytes);
+ serial_busy = false;
+
return true;
}
+volatile bool SerialIsBusy(void)
+{
+ return serial_busy;
+}
+
#ifdef SERIAL_INTERFACE
void Serial_printf(const char* str, ...)
{
diff --git a/Source/Serial.h b/Source/Serial.h
index 7323d3b..30ad901 100644
--- a/Source/Serial.h
+++ b/Source/Serial.h
@@ -24,6 +24,7 @@
void SerialInit(void);
bool SerialRead(uint8_t* ptrArray, size_t nBytes);
bool SerialWrite(void* ptrArray, size_t nBytes);
+volatile bool SerialIsBusy(void);
#ifdef SERIAL_INTERFACE
void Serial_printf(const char* str, ...);
diff --git a/Source/System.c b/Source/System.c
index eae1148..f1e5471 100644
--- a/Source/System.c
+++ b/Source/System.c
@@ -45,6 +45,9 @@ static bool emergency_mode;
static volatile bool system_busy;
//Timer array.
static TYPE_TIMER timer_array[SYSTEM_MAX_TIMERS];
+// When true, it draws a rectangle on top of all primitives with
+// information for development purposes.
+static bool devmenu_flag;
/* *******************************************************************
*
@@ -65,7 +68,8 @@ void SystemInit(void)
//Reset 1 second timer
one_second_timer = 0;
//PSXSDK init
- PSX_InitEx(PSX_INIT_SAVESTATE | PSX_INIT_CD);
+ //PSX_InitEx(PSX_INIT_SAVESTATE | PSX_INIT_CD);
+ PSX_InitEx(0);
//Graphics init
GsInit();
//Clear VRAM
@@ -94,6 +98,8 @@ void SystemInit(void)
MemCardInit();
//Initial value for system_busy
system_busy = false;
+ //Development menu flag
+ devmenu_flag = false;
GfxSetGlobalLuminance(NORMAL_LUMINANCE);
@@ -189,7 +195,6 @@ bool SystemRefreshNeeded(void)
void ISR_SystemDefaultVBlank(void)
{
refresh_needed = true;
- SystemIncreaseGlobalTimer();
}
/* *******************************************************************
@@ -360,7 +365,7 @@ bool SystemLoadFileToBuffer(char* fname, uint8_t* buffer, uint32_t szBuffer)
#ifdef SERIAL_INTERFACE
uint8_t fileSizeBuffer[sizeof(uint32_t)] = {0};
uint32_t i;
-#else
+#else // SERIAL_INTERFACE
FILE *f;
#endif // SERIAL_INTERFACE
int32_t size = 0;
@@ -375,11 +380,9 @@ bool SystemLoadFileToBuffer(char* fname, uint8_t* buffer, uint32_t szBuffer)
}
memset(buffer,0,szBuffer);
-
- system_busy = true;
#ifdef SERIAL_INTERFACE
- Serial_printf("%s", fname);
+ Serial_printf("#%s@", fname);
SerialRead(fileSizeBuffer, sizeof(uint32_t) );
@@ -409,7 +412,9 @@ bool SystemLoadFileToBuffer(char* fname, uint8_t* buffer, uint32_t szBuffer)
SerialWrite(ACK_BYTE_STRING, sizeof(uint8_t)); // Write ACK
}
-#else
+#else // SERIAL_INTERFACE
+
+ system_busy = true;
SystemDisableVBlankInterrupt();
@@ -441,10 +446,10 @@ bool SystemLoadFileToBuffer(char* fname, uint8_t* buffer, uint32_t szBuffer)
SystemEnableVBlankInterrupt();
+ system_busy = false;
+
#endif // SERIAL_INTERFACE
- system_busy = false;
-
Serial_printf("File \"%s\" loaded successfully!\n",fname);
return true;
@@ -784,6 +789,18 @@ void SystemTimerRemove(TYPE_TIMER* timer)
timer->repeat_flag = false;
}
+/* ****************************************************************************************
+ *
+ * @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".
+ *
+ * @return: true if they are equal, false otherwise.
+ *
+ * ****************************************************************************************/
+
bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz)
{
size_t i;
@@ -799,10 +816,20 @@ bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz)
return true;
}
+/* ****************************************************************************************
+ *
+ * @name void SystemPrintStackPointerAddress(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Prints stack usage in percentage via dprintf calls.
+ *
+ * ****************************************************************************************/
+
void SystemPrintStackPointerAddress(void)
{
#ifdef PSXSDK_DEBUG // Used to avoid unused variable warning
- void * ptr = NULL;
+ 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));
@@ -822,6 +849,17 @@ void SystemPrintStackPointerAddress(void)
}
+/* ****************************************************************************************
+ *
+ * @name void SystemCheckStack(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @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;
@@ -838,6 +876,18 @@ void SystemCheckStack(void)
}
}
+
+/* ****************************************************************************************
+ *
+ * @name void SystemSetStackPattern(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @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;
@@ -847,6 +897,18 @@ void SystemSetStackPattern(void)
*ptrStack = END_STACK_PATTERN;
}
+/* ****************************************************************************************
+ *
+ * @name int32_t SystemIndexOfStringArray(char* str, char** array)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @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 i;
@@ -865,6 +927,18 @@ int32_t SystemIndexOfStringArray(char* str, char** array)
return -1;
}
+/* ****************************************************************************************
+ *
+ * @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.
+ *
+ * @return Index for a variable "value" inside "array". -1 if it could not be found.
+ *
+ * ****************************************************************************************/
+
int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz)
{
int32_t i;
@@ -880,6 +954,20 @@ int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz)
return -1;
}
+/* ****************************************************************************************
+ *
+ * @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.
+ * "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.
+ *
+ * ****************************************************************************************/
+
+
int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz)
{
int32_t i;
@@ -895,6 +983,17 @@ int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t
return -1;
}
+/* ****************************************************************************************
+ *
+ * @name void SystemCyclicHandler(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: It calls system handlers once an execution cycle has finished.
+ *
+ *
+ * ****************************************************************************************/
+
void SystemCyclicHandler(void)
{
if(UpdatePads() == false)
@@ -905,6 +1004,8 @@ void SystemCyclicHandler(void)
{
SystemSetEmergencyMode(false);
}
+
+ SystemIncreaseGlobalTimer();
SystemRunTimers();
@@ -917,12 +1018,183 @@ void SystemCyclicHandler(void)
SystemCheckStack();
}
+/* ****************************************************************************************
+ *
+ * @name void SystemDisableVBlankInterrupt(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @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.
+ *
+ * ****************************************************************************************/
+
void SystemDisableVBlankInterrupt(void)
{
I_MASK &= ~(0x0001);
}
+/* ****************************************************************************************
+ *
+ * @name void SystemEnableVBlankInterrupt(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Reportedly, this routine enables VBLANK interrupt flag.
+ *
+ *
+ * ****************************************************************************************/
+
void SystemEnableVBlankInterrupt(void)
{
I_MASK |= (0x0001);
}
+
+/* ****************************************************************************************
+ *
+ * @name void SystemReturnToLoader(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Deinitializes PSXSDK library and returns to OpenSend loader,
+ * located at memory address 0x801A0000
+ *
+ * ****************************************************************************************/
+
+void SystemReturnToLoader(void)
+{
+ Serial_printf("Returning to loader...\n");
+
+ EndAnimation();
+
+ PSX_DeInit();
+
+ __asm__("j 0x801A0000");
+}
+
+/* ****************************************************************************************
+ *
+ * @name void SystemDevMenuToggle(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: It toggles a flag called "devmenu_flag" which, if true, shows information on
+ * top of all drawn primitives for debugging/development purposes.
+ *
+ * ****************************************************************************************/
+
+void SystemDevMenuToggle(void)
+{
+ devmenu_flag = devmenu_flag? false: true;
+
+ DEBUG_PRINT_VAR(devmenu_flag);
+}
+
+/* ****************************************************************************************
+ *
+ * @name void SystemDevMenu(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief: Shows information on top of all drawn primitives for debugging/development purposes.
+ *
+ * ****************************************************************************************/
+
+void SystemDevMenu(void)
+{
+ enum
+ {
+ DEVMENU_BG_W = 256,
+ DEVMENU_BG_X = (X_SCREEN_RESOLUTION >> 1) - (DEVMENU_BG_W >> 1),
+ DEVMENU_BG_Y = 32,
+ DEVMENU_BG_H = 128,
+
+ DEVMENU_BG_R = 0,
+ DEVMENU_BG_G = 128,
+ DEVMENU_BG_B = 32,
+ };
+
+ enum
+ {
+ DEVMENU_TEXT_GAP = 8,
+
+ DEVMENU_PAD1_STATUS_TEXT_X = DEVMENU_BG_X + DEVMENU_TEXT_GAP,
+ DEVMENU_PAD1_STATUS_TEXT_Y = DEVMENU_BG_Y + DEVMENU_TEXT_GAP,
+
+ DEVMENU_PAD1_TYPE_TEXT_X = DEVMENU_PAD1_STATUS_TEXT_X,
+ DEVMENU_PAD1_TYPE_TEXT_Y = DEVMENU_PAD1_STATUS_TEXT_Y + DEVMENU_TEXT_GAP,
+
+ DEVMENU_PAD1_ID_TEXT_X = DEVMENU_PAD1_STATUS_TEXT_X,
+ DEVMENU_PAD1_ID_TEXT_Y = DEVMENU_PAD1_TYPE_TEXT_Y + DEVMENU_TEXT_GAP,
+
+ DEVMENU_PAD2_STATUS_TEXT_X = DEVMENU_PAD1_ID_TEXT_X,
+ DEVMENU_PAD2_STATUS_TEXT_Y = DEVMENU_PAD1_ID_TEXT_Y + (DEVMENU_TEXT_GAP << 1), // Leave a bigger gap here
+
+ DEVMENU_PAD2_TYPE_TEXT_X = DEVMENU_PAD2_STATUS_TEXT_X,
+ DEVMENU_PAD2_TYPE_TEXT_Y = DEVMENU_PAD2_STATUS_TEXT_Y + DEVMENU_TEXT_GAP,
+
+ DEVMENU_PAD2_ID_TEXT_X = DEVMENU_PAD2_TYPE_TEXT_X,
+ DEVMENU_PAD2_ID_TEXT_Y = DEVMENU_PAD2_TYPE_TEXT_Y + DEVMENU_TEXT_GAP,
+
+ DEVMENU_ROOTCNT0_TEXT_X = DEVMENU_PAD2_ID_TEXT_X,
+ DEVMENU_ROOTCNT0_TEXT_Y = DEVMENU_PAD2_ID_TEXT_Y + DEVMENU_TEXT_GAP,
+ };
+
+ if(devmenu_flag == true)
+ {
+ 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);
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD1_STATUS_TEXT_X,
+ DEVMENU_PAD1_STATUS_TEXT_Y,
+ "Pad1 connected = %d",
+ PadOneConnected() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD1_TYPE_TEXT_X,
+ DEVMENU_PAD1_TYPE_TEXT_Y,
+ "Pad1 type = 0x%02X",
+ PadOneGetType() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD1_ID_TEXT_X,
+ DEVMENU_PAD1_ID_TEXT_Y,
+ "Pad1 ID = 0x%02X",
+ PadOneGetID() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD2_STATUS_TEXT_X,
+ DEVMENU_PAD2_STATUS_TEXT_Y,
+ "Pad2 connected = %d",
+ PadTwoConnected() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD2_TYPE_TEXT_X,
+ DEVMENU_PAD2_TYPE_TEXT_Y,
+ "Pad2 type = 0x%02X",
+ PadTwoGetType() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_PAD2_ID_TEXT_X,
+ DEVMENU_PAD2_ID_TEXT_Y,
+ "Pad2 ID = 0x%02X",
+ PadTwoGetID() );
+
+ FontPrintText( &SmallFont,
+ DEVMENU_ROOTCNT0_TEXT_X,
+ DEVMENU_ROOTCNT0_TEXT_Y,
+ "Timer0 = 0x%04X",
+ (uint16_t)((*(uint32_t*)0x1F801100) & 0x00FF) );
+ }
+}
diff --git a/Source/System.h b/Source/System.h
index 9192d3c..4bec203 100644
--- a/Source/System.h
+++ b/Source/System.h
@@ -132,6 +132,12 @@ void SystemEnableVBlankInterrupt();
void SystemDisableVBlankInterrupt();
+void SystemReturnToLoader(void);
+
+void SystemDevMenuToggle(void);
+
+void SystemDevMenu(void);
+
/* **************************************
* Global Variables *
* **************************************/