1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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 Error() */
39 #define ERR_DEBUG (1 << 0)
40 #define ERR_INFO (1 << 1)
41 #define ERR_INFO_LINE (1 << 2)
42 #define ERR_WARN (1 << 3)
43 #define ERR_EXIT (1 << 4)
44 #define ERR_HELP (1 << 5)
45 #define ERR_SOUND_SERVER (1 << 6)
46 #define ERR_NETWORK_SERVER (1 << 7)
47 #define ERR_NETWORK_CLIENT (1 << 8)
48 #define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER)
49 #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP)
50 #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER)
51 #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER)
52 #define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT)
54 /* values for getFile...() and putFile...() */
55 #define BYTE_ORDER_BIG_ENDIAN 0
56 #define BYTE_ORDER_LITTLE_ENDIAN 1
58 /* values for cursor bitmap creation */
59 #define BIT_ORDER_MSB 0
60 #define BIT_ORDER_LSB 1
62 /* values for createDirectory() */
63 #define PERMS_PRIVATE 0
64 #define PERMS_PUBLIC 1
66 /* values for general file handling stuff */
67 #define MAX_FILENAME_LEN 256
68 #define MAX_LINE_LEN 1024
70 /* values for general username handling stuff */
71 #define MAX_USERNAME_LEN 1024
73 #if defined(PLATFORM_ANDROID)
74 /* values for Android asset handling */
75 #define ASSET_TOC_BASENAME ".toc"
79 /* structure definitions */
87 #if defined(PLATFORM_ANDROID)
88 boolean file_is_asset;
89 SDL_RWops *asset_file;
104 DirectoryEntry *dir_entry;
106 #if defined(PLATFORM_ANDROID)
107 boolean directory_is_asset;
108 SDL_RWops *asset_toc_file;
114 /* function definitions */
116 void fprintf_line(FILE *, char *, int);
117 void fprintf_line_with_prefix(FILE *, char *, char *, int);
118 void printf_line(char *, int);
119 void printf_line_with_prefix(char *, char *, int);
121 void Print(char *, ...);
122 void PrintNoLog(char *, ...);
123 void PrintLine(char *, int);
124 void PrintLineWithPrefix(char *, char *, int);
126 char *int2str(int, int);
127 char *i_to_a(unsigned int);
128 int log_2(unsigned int);
130 boolean getTokenValueFromString(char *, char **, char **);
132 void InitCounter(void);
133 unsigned int Counter(void);
134 void Delay(unsigned int);
135 boolean DelayReachedExt(unsigned int *, unsigned int, unsigned int);
136 boolean FrameReached(unsigned int *, unsigned int);
137 boolean DelayReached(unsigned int *, unsigned int);
138 void ResetDelayCounterExt(unsigned int *, unsigned int);
139 void ResetFrameCounter(unsigned int *);
140 void ResetDelayCounter(unsigned int *);
141 int WaitUntilDelayReached(unsigned int *, unsigned int);
142 void SkipUntilDelayReached(unsigned int *, unsigned int, int *, int);
144 unsigned int init_random_number(int, int);
145 unsigned int get_random_number(int, int);
147 char *getLoginName(void);
148 char *getRealName(void);
150 time_t getFileTimestampEpochSeconds(char *);
152 char *getBasePath(char *);
153 char *getBaseName(char *);
154 char *getBaseNamePtr(char *);
155 char *getBaseNameNoSuffix(char *);
157 char *getStringCat2WithSeparator(char *, char *, char *);
158 char *getStringCat3WithSeparator(char *, char *, char *, char *);
159 char *getStringCat2(char *, char *);
160 char *getStringCat3(char *, char *, char *);
161 char *getPath2(char *, char *);
162 char *getPath3(char *, char *, char*);
163 char *getImg2(char *, char *);
164 char *getImg3(char *, char *, char*);
165 char *getStringCopy(const char *);
166 char *getStringCopyN(const char *, int);
167 char *getStringCopyNStatic(const char *, int);
168 char *getStringToLower(const char *);
169 void setString(char **, char *);
170 boolean strEqual(char *, char *);
171 boolean strEqualN(char *, char *, int);
172 boolean strPrefix(char *, char *);
173 boolean strSuffix(char *, char *);
174 boolean strPrefixLower(char *, char *);
175 boolean strSuffixLower(char *, char *);
177 void GetOptions(int, char **,
178 void (*print_usage_function)(void),
179 void (*print_version_function)(void));
181 void SetError(char *, ...);
182 char *GetError(void);
183 void Error(int, char *, ...);
185 void *checked_malloc(unsigned int);
186 void *checked_calloc(unsigned int);
187 void *checked_realloc(void *, unsigned int);
188 void checked_free(void *);
189 void clear_mem(void *, unsigned int);
191 void swap_numbers(int *, int *);
192 void swap_number_pairs(int *, int *, int *, int *);
194 int getFile8BitInteger(File *);
195 int putFile8BitInteger(FILE *, int);
196 int getFile16BitInteger(File *, int);
197 int putFile16BitInteger(FILE *, int, int);
198 int getFile32BitInteger(File *, int);
199 int putFile32BitInteger(FILE *, int, int);
201 boolean getFileChunk(File *, char *, int *, int);
202 int putFileChunk(FILE *, char *, int, int);
203 int getFileVersion(File *);
204 int putFileVersion(FILE *, int);
206 void ReadBytesFromFile(File *, byte *, unsigned int);
207 void WriteBytesToFile(FILE *, byte *, unsigned int);
209 void ReadUnusedBytesFromFile(File *, unsigned int);
210 void WriteUnusedBytesToFile(FILE *, unsigned int);
212 #define getFile8Bit(f) getFile8BitInteger(f)
213 #define putFile8Bit(f,x) putFile8BitInteger(f,x)
214 #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
215 #define getFile16BitLE(f) getFile16BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
216 #define putFile16BitBE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
217 #define putFile16BitLE(f,x) putFile16BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
218 #define getFile32BitBE(f) getFile32BitInteger(f,BYTE_ORDER_BIG_ENDIAN)
219 #define getFile32BitLE(f) getFile32BitInteger(f,BYTE_ORDER_LITTLE_ENDIAN)
220 #define putFile32BitBE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_BIG_ENDIAN)
221 #define putFile32BitLE(f,x) putFile32BitInteger(f,x,BYTE_ORDER_LITTLE_ENDIAN)
223 #define getFileChunkBE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
224 #define getFileChunkLE(f,s,x) getFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
225 #define putFileChunkBE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_BIG_ENDIAN)
226 #define putFileChunkLE(f,s,x) putFileChunk(f,s,x,BYTE_ORDER_LITTLE_ENDIAN)
228 char *getKeyNameFromKey(Key);
229 char *getX11KeyNameFromKey(Key);
230 Key getKeyFromKeyName(char *);
231 Key getKeyFromX11KeyName(char *);
232 char getCharFromKey(Key);
233 char getValidConfigValueChar(char);
235 int get_integer_from_string(char *);
236 boolean get_boolean_from_string(char *);
237 int get_switch3_from_string(char *);
238 int get_player_nr_from_string(char *);
240 ListNode *newListNode(void);
241 void addNodeToList(ListNode **, char *, void *);
242 void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
243 ListNode *getNodeFromKey(ListNode *, char *);
244 int getNumNodes(ListNode *);
246 File *openFile(char *, char *);
247 int closeFile(File *);
248 int checkEndOfFile(File *);
249 size_t readFile(File *, void *, size_t, size_t);
250 size_t writeFile(File *, void *, size_t, size_t);
251 int seekFile(File *, long, int);
252 int getByteFromFile(File *);
253 char *getStringFromFile(File *, char *, int);
254 int copyFile(char *, char *);
256 Directory *openDirectory(char *);
257 int closeDirectory(Directory *);
258 DirectoryEntry *readDirectory(Directory *);
259 void freeDirectoryEntry(DirectoryEntry *);
261 boolean directoryExists(char *);
262 boolean fileExists(char *);
263 boolean FileIsGraphic(char *);
264 boolean FileIsSound(char *);
265 boolean FileIsMusic(char *);
266 boolean FileIsArtworkType(char *, int);
268 char *get_mapped_token(char *);
270 int get_parameter_value(char *, char *, int);
272 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *,
273 struct ConfigTypeInfo *,
275 void LoadArtworkConfig(struct ArtworkListInfo *);
276 void ReloadCustomArtworkList(struct ArtworkListInfo *);
277 void FreeCustomArtworkLists(struct ArtworkListInfo *);
279 char *getLogFilename(char *);
281 void CloseLogFiles();
282 void DumpLogFile(int);
284 void NotifyUserAboutErrorFile();
287 void debug_print_timestamp(int, char *);
289 void print_timestamp_init(char *);
290 void print_timestamp_time(char *);
291 void print_timestamp_done(char *);