1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
22 // values for InitCounter() and Counter()
23 #define INIT_COUNTER 0
24 #define READ_COUNTER 1
26 // values for InitRND()
27 #define NEW_RANDOMIZE 0
29 #define RANDOM_ENGINE 0
30 #define RANDOM_SIMPLE 1
32 #define InitEngineRandom(seed) init_random_number(RANDOM_ENGINE, seed)
33 #define InitSimpleRandom(seed) init_random_number(RANDOM_SIMPLE, seed)
34 #define GetEngineRandom(max) get_random_number(RANDOM_ENGINE, max)
35 #define GetSimpleRandom(max) get_random_number(RANDOM_SIMPLE, max)
37 // values for getFile...() and putFile...()
38 #define BYTE_ORDER_BIG_ENDIAN 0
39 #define BYTE_ORDER_LITTLE_ENDIAN 1
41 // values for cursor bitmap creation
42 #define BIT_ORDER_MSB 0
43 #define BIT_ORDER_LSB 1
45 // values for createDirectory()
46 #define PERMS_PRIVATE 0
47 #define PERMS_PUBLIC 1
49 // values for general file handling stuff
50 #define MAX_FILENAME_LEN 256
51 #define MAX_LINE_LEN 1024
53 // values for general username handling stuff
54 #define MAX_USERNAME_LEN 1024
56 #if defined(PLATFORM_ANDROID)
57 // values for Android asset handling
58 #define ASSET_TOC_BASENAME ".toc"
62 // structure definitions
70 #if defined(PLATFORM_ANDROID)
71 boolean file_is_asset;
72 SDL_RWops *asset_file;
87 DirectoryEntry *dir_entry;
89 #if defined(PLATFORM_ANDROID)
90 boolean directory_is_asset;
91 SDL_RWops *asset_toc_file;
97 // function definitions
99 void fprintf_line(FILE *, char *, int);
100 void fprintf_line_with_prefix(FILE *, char *, char *, int);
101 void printf_line(char *, int);
102 void printf_line_with_prefix(char *, char *, int);
104 void Print(char *, ...);
105 void PrintNoLog(char *, ...);
106 void PrintLine(char *, int);
107 void PrintLineWithPrefix(char *, char *, int);
109 void DebugContinued(char *, char *, ...);
110 void Debug(char *, char *, ...);
111 void Info(char *, ...);
112 void Warn(char *, ...);
113 void Error(char *, ...);
114 void Fail(char *, ...);
115 void FailWithHelp(char *, ...);
117 char *int2str(int, int);
118 char *i_to_a(unsigned int);
119 int log_2(unsigned int);
121 boolean getTokenValueFromString(char *, char **, char **);
123 void InitCounter(void);
124 unsigned int Counter(void);
125 void Delay(unsigned int);
126 boolean DelayReachedExt(unsigned int *, unsigned int, unsigned int);
127 boolean FrameReached(unsigned int *, unsigned int);
128 boolean DelayReached(unsigned int *, unsigned int);
129 void ResetDelayCounterExt(unsigned int *, unsigned int);
130 void ResetFrameCounter(unsigned int *);
131 void ResetDelayCounter(unsigned int *);
132 int WaitUntilDelayReached(unsigned int *, unsigned int);
133 void SkipUntilDelayReached(unsigned int *, unsigned int, int *, int);
135 unsigned int init_random_number(int, int);
136 unsigned int get_random_number(int, int);
138 #if defined(PLATFORM_UNIX)
139 char *getUnixLoginName(void);
140 char *getUnixRealName(void);
141 char *getUnixHomeDir(void);
144 char *getLoginName(void);
145 char *getRealName(void);
146 char *getFixedUserName(char *);
148 time_t getFileTimestampEpochSeconds(char *);
150 char *getBasePath(char *);
151 char *getBaseName(char *);
152 char *getBaseNamePtr(char *);
153 char *getBaseNameNoSuffix(char *);
155 char *getStringCat2WithSeparator(char *, char *, char *);
156 char *getStringCat3WithSeparator(char *, char *, char *, char *);
157 char *getStringCat2(char *, char *);
158 char *getStringCat3(char *, char *, char *);
159 char *getPath2(char *, char *);
160 char *getPath3(char *, char *, char*);
161 char *getImg2(char *, char *);
162 char *getImg3(char *, char *, char*);
163 char *getStringCopy(const char *);
164 char *getStringCopyN(const char *, int);
165 char *getStringCopyNStatic(const char *, int);
166 char *getStringToLower(const char *);
167 void setString(char **, char *);
168 boolean strEqual(char *, char *);
169 boolean strEqualN(char *, char *, int);
170 boolean strPrefix(char *, char *);
171 boolean strSuffix(char *, char *);
172 boolean strPrefixLower(char *, char *);
173 boolean strSuffixLower(char *, char *);
175 void GetOptions(int, char **,
176 void (*print_usage_function)(void),
177 void (*print_version_function)(void));
179 void *checked_malloc(unsigned int);
180 void *checked_calloc(unsigned int);
181 void *checked_realloc(void *, unsigned int);
182 void checked_free(void *);
183 void clear_mem(void *, unsigned int);
185 void swap_numbers(int *, int *);
186 void swap_number_pairs(int *, int *, int *, int *);
188 int getFile8BitInteger(File *);
189 int putFile8BitInteger(FILE *, int);
190 int getFile16BitInteger(File *, int);
191 int putFile16BitInteger(FILE *, int, int);
192 int getFile32BitInteger(File *, int);
193 int putFile32BitInteger(FILE *, int, int);
195 boolean getFileChunk(File *, char *, int *, int);
196 int putFileChunk(FILE *, char *, int, int);
197 int getFileVersion(File *);
198 int putFileVersion(FILE *, int);
200 void ReadBytesFromFile(File *, byte *, unsigned int);
201 void WriteBytesToFile(FILE *, byte *, unsigned int);
203 void ReadUnusedBytesFromFile(File *, unsigned int);
204 void WriteUnusedBytesToFile(FILE *, unsigned int);
206 #define getFile8Bit(f) getFile8BitInteger(f)
207 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
208 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
209 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
210 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
211 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
212 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
213 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
214 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
215 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
217 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
218 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
219 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
220 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
222 char *getKeyNameFromKey(Key);
223 char *getX11KeyNameFromKey(Key);
224 Key getKeyFromKeyName(char *);
225 Key getKeyFromX11KeyName(char *);
226 char getCharFromKey(Key);
227 char getValidConfigValueChar(char);
229 int get_integer_from_string(char *);
230 boolean get_boolean_from_string(char *);
231 int get_switch3_from_string(char *);
232 int get_player_nr_from_string(char *);
234 ListNode *newListNode(void);
235 void addNodeToList(ListNode **, char *, void *);
236 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
237 ListNode *getNodeFromKey(ListNode *, char *);
238 int getNumNodes(ListNode *);
240 File *openFile(char *, char *);
241 int closeFile(File *);
242 int checkEndOfFile(File *);
243 size_t readFile(File *, void *, size_t, size_t);
244 size_t writeFile(File *, void *, size_t, size_t);
245 int seekFile(File *, long, int);
246 int getByteFromFile(File *);
247 char *getStringFromFile(File *, char *, int);
248 int copyFile(char *, char *);
250 Directory *openDirectory(char *);
251 int closeDirectory(Directory *);
252 DirectoryEntry *readDirectory(Directory *);
253 void freeDirectoryEntry(DirectoryEntry *);
255 boolean directoryExists(char *);
256 boolean fileExists(char *);
257 boolean FileIsGraphic(char *);
258 boolean FileIsSound(char *);
259 boolean FileIsMusic(char *);
260 boolean FileIsArtworkType(char *, int);
262 char *get_mapped_token(char *);
264 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
265 struct ConfigTypeInfo *,
267 void LoadArtworkConfig(struct ArtworkListInfo *);
268 void ReloadCustomArtworkList(struct ArtworkListInfo *);
269 void FreeCustomArtworkLists(struct ArtworkListInfo *);
271 char *getLogFilename(char *);
272 void OpenLogFiles(void);
273 void CloseLogFiles(void);
274 void DumpLogFile(int);
276 void NotifyUserAboutErrorFile(void);
279 void debug_print_timestamp(int, char *);
281 void print_timestamp_init(char *);
282 void print_timestamp_time(char *);
283 void print_timestamp_done(char *);