aboutsummaryrefslogtreecommitdiff
path: root/Source/System.h
blob: 12c0079e877d1ab6e86bd5978f65c41015b863b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef SYSTEM_HEADER__
#define SYSTEM_HEADER__

/* **************************************
 * 	Includes							*
 * **************************************/
#include "Global_Inc.h"
#include "GameStructures.h"

/* **************************************
 * 	Defines								*
 * **************************************/
#define TIMER_PRESCALER_1_SECOND    10
#define TIMER_PRESCALER_1_MINUTE    (TIMER_PRESCALER_1_SECOND * 60)

#define ARRAY_SIZE(x)   (sizeof ((x)) / sizeof ((x[0])))

/* **************************************
 * 	Global Prototypes					*
 * **************************************/
// Calls PSXSDK init routines
void SystemInit(void);

// Sets default VSync (only sets VBlank flag)
void ISR_SystemDefaultVBlank(void);

// Calls srand() using current global_timer value as seed
void SystemSetRandSeed(void);

// Returns VSync flag value
bool SystemRefreshNeeded(void);

// Loads a file into system's internal buffer
bool SystemLoadFile(const char*fname);

// Loads a file into desired buffer
bool SystemLoadFileToBuffer(const char* fname, uint8_t* buffer, uint32_t szBuffer);

// Clears VSync flag after each frame
void SystemDisableScreenRefresh(void);

// Returns file buffer address
uint8_t* SystemGetBufferAddress(void);

// Tells whether srand() has been called using a pseudo-random value
bool SystemIsRandSeedSet(void);

// To be called from GfxDrawScene after each cycle
void SystemRunTimers(void);

// 1 cycle-length flag with a frequency of 1 Hz
bool System1SecondTick(void);

// 1 cycle-length flag with a frequency of 2 Hz
bool System500msTick(void);

// 1 cycle-length flag with a frequency of 10 Hz
bool System100msTick(void);

// Returns random value between given minimum and maximum values
uint32_t SystemRand(uint32_t min, uint32_t max);

// Increases global timer by 1 step
void SystemIncreaseGlobalTimer(void);

// Sets value to emergency mode flag
void SystemSetEmergencyMode(bool value);

// Returns emergency mode flag state
bool SystemGetEmergencyMode(void);

volatile uint64_t SystemGetGlobalTimer(void);

// Returns whether critical section of code is being entered
volatile bool SystemIsBusy(void);

// Returns whether indicated value is contained inside buffer
bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz);

// Overload for uint16_t
bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz);

// Compares two arrays of unsigned short type.
bool SystemArrayCompare(unsigned short* arr1, unsigned short* arr2, size_t sz);

// Prints stack pointer address using Serial_printf()
void SystemPrintStackPointerAddress(void);

// Checks if a 32-bit pattern set at the end of the stack has been
// accidentally modified by program flow.
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);

// Function overload for uint16_t data type.
int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz);

// Function overload for uint8_t data type.
int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz);

// Returns frames per second.
volatile uint8_t SystemGetFPS(void);

// Increase temp_fps in order to calculate frame rate.
void SystemAcknowledgeFrame(void);

void SystemCyclicHandler(void);

void SystemClearFileBuffer(void);

void SystemEnableVBlankInterrupt(void);

void SystemDisableVBlankInterrupt(void);

void SystemEnableRCnt2Interrupt(void);

void SystemDisableRCnt2Interrupt(void);

void SystemReturnToLoader(void);

void SystemDevMenuToggle(void);

void SystemDevMenu(void);

void SystemCalculateSine(void);

unsigned char SystemGetSineValue(void);

// Fills str with only file name and extension given input file path.
// For example: "FOLDER\\FOLDER\\MYFILE.EXT;1" -> "MYFILE.EXT"
void SystemGetFileBasename(const char* fileName, char* str, const size_t sz);

/* **************************************
 * 	Global Variables					*
 * **************************************/
#endif //SYSTEM_HEADER__