annotate util.h @ 995:2bc27415565b

Fix some stuff with interrupt timing. The change in adjust_int_cycle gets Overdrive working again (vint was not being preferred over hint in some cases). One of the changes seems to have broken Fatal Rewind again, but no other regressions that I can see.
author Michael Pavone <pavone@retrodev.com>
date Sat, 30 Apr 2016 08:37:55 -0700
parents 1618d3676a35
children 51885857c019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #ifndef UTIL_H_
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #define UTIL_H_
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <stdio.h>
957
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
5 #include <time.h>
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
7 typedef struct {
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
8 char *name;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
9 uint8_t is_dir;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
10 } dir_entry;
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
11
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 //Utility functions
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 //Allocates a new string containing the concatenation of first and second
876
540cc4a7d626 Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
15 char * alloc_concat(char const * first, char const * second);
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 //Allocates a new string containing the concatenation of the strings pointed to by parts
876
540cc4a7d626 Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
17 char * alloc_concat_m(int num_parts, char const ** parts);
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 //Returns the size of a file using fseek and ftell
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 long file_size(FILE * f);
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 //Strips whitespace and non-printable characters from the beginning and end of a string
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 char * strip_ws(char * text);
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
22 //Inserts a null after the first word, returns a pointer to the second word
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 char * split_keyval(char * text);
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
24 //Returns the basename of a path with th extension (if any) stripped
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
25 char * basename_no_extension(char *path);
768
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
26 //Gets the smallest power of two that is >= a certain value, won't work for values > 0x80000000
2f48a3c187c6 Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
27 uint32_t nearest_pow2(uint32_t val);
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
28 //Should be called by main with the value of argv[0] for use by get_exe_dir
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
29 void set_exe_str(char * str);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
30 //Returns the directory the executable is in
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
31 char * get_exe_dir();
742
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
32 //Returns the user's home directory
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
33 char * get_home_dir();
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
34 //Returns an appropriate path for storing config files
876
540cc4a7d626 Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
35 char const *get_config_dir();
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
36 //Returns an appropriate path for saving non-config data like savestates
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
37 char const *get_save_dir();
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
38 //Reads a file bundled with the executable
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
39 char *read_bundled_file(char *name, long *sizeret);
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
40 //Retunrs an array of normal files and directories residing in a directory
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
41 dir_entry *get_dir_list(char *path, size_t *numret);
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
42 //Frees a dir list returned by get_dir_list
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
43 void free_dir_list(dir_entry *list, size_t numentries);
957
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
44 //Gets the modification time of a file
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
45 time_t get_modification_time(char *path);
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
46 //Recusrively creates a directory if it does not exist
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
47 int ensure_dir_exists(char *path);
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
48 //Returns the contents of a symlink in a newly allocated string
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
49 char * readlink_alloc(char * path);
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
50 //Prints an error message to stderr and to a message box if not in headless mode and then exits
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
51 void fatal_error(char *format, ...);
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
52 //Prints an information message to stdout and to a message box if not in headless mode and not attached to a console
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 768
diff changeset
53 void info_message(char *format, ...);
794
792be135d3af Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
54 //Prints an information message to stderr and to a message box if not in headless mode and not attached to a console
792be135d3af Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
55 void warning(char *format, ...);
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 #endif //UTIL_H_