src/mess/tools/castool/stubs.c
| r11467 | r11468 | |
| 1 | | #include "emu.h" |
| 2 | | #include "emuopts.h" |
| 3 | | #include "pool.h" |
| 4 | | #include <ctype.h> |
| 5 | | #include <stdarg.h> |
| 6 | | |
| 7 | | /* Variables to hold the status of various game options */ |
| 8 | | static FILE *errorlog; |
| 9 | | |
| 10 | | const game_driver *const drivers[1] = { NULL }; |
| 11 | | int rompath_extra; |
| 12 | | int history_filename; |
| 13 | | int mameinfo_filename; |
| 14 | | |
| 15 | | void CLIB_DECL logerror(const char *text,...) |
| 16 | | { |
| 17 | | va_list arg; |
| 18 | | va_start(arg,text); |
| 19 | | if (errorlog) |
| 20 | | vfprintf(errorlog,text,arg); |
| 21 | | va_end(arg); |
| 22 | | } |
| 23 | | |
| 24 | | /* ----------------------------------------------------------------------- */ |
| 25 | | /* total hack */ |
| 26 | | |
| 27 | | file_error mame_fopen(const char *searchpath, const char *filename, UINT32 openflags, emu_file **file) |
| 28 | | { |
| 29 | | char buffer[2048]; |
| 30 | | snprintf(buffer, sizeof(buffer), "crc/%s", filename); |
| 31 | | *file = (emu_file *) fopen(buffer, "r"); |
| 32 | | return FILERR_NONE; |
| 33 | | } |
| 34 | | |
| 35 | | char *mame_fgets(char *s, int n, emu_file *file) |
| 36 | | { |
| 37 | | return fgets(s, n, (FILE *) file); |
| 38 | | } |
| 39 | | |
| 40 | | UINT32 mame_fwrite(emu_file *file, const void *buffer, UINT32 length) |
| 41 | | { |
| 42 | | return fwrite(buffer, 1, length, (FILE *) file); |
| 43 | | } |
| 44 | | |
| 45 | | void mame_fclose(emu_file *file) |
| 46 | | { |
| 47 | | fclose((FILE *) file); |
| 48 | | } |
| 49 | | |
| 50 | | int CLIB_DECL mame_fprintf(emu_file *f, const char *fmt, ...) |
| 51 | | { |
| 52 | | int rc; |
| 53 | | va_list va; |
| 54 | | va_start(va, fmt); |
| 55 | | rc = vfprintf(stderr, fmt, va); |
| 56 | | va_end(va); |
| 57 | | return rc; |
| 58 | | } |
| 59 | | |
| 60 | | void mame_printf_error(const char *format, ...) |
| 61 | | { |
| 62 | | } |
| 63 | | |
| 64 | | void mame_printf_warning(const char *format, ...) |
| 65 | | { |
| 66 | | } |
| 67 | | |
| 68 | | void mame_printf_info(const char *format, ...) |
| 69 | | { |
| 70 | | } |
| 71 | | |
| 72 | | void mame_printf_debug(const char *format, ...) |
| 73 | | { |
| 74 | | } |
| 75 | | |
| 76 | | |
| 77 | | |
| 78 | | /*************************************************************************** |
| 79 | | TYPE DEFINITIONS |
| 80 | | ***************************************************************************/ |
| 81 | | |
| 82 | | enum _memory_block_overlap |
| 83 | | { |
| 84 | | OVERLAP_NONE, |
| 85 | | OVERLAP_PARTIAL, |
| 86 | | OVERLAP_FULL |
| 87 | | }; |
| 88 | | typedef enum _memory_block_overlap memory_block_overlap; |
| 89 | | |
| 90 | | |
| 91 | | |
| 92 | | /*************************************************************************** |
| 93 | | GLOBAL VARIABLES |
| 94 | | ***************************************************************************/ |
| 95 | | |
| 96 | | /* pool list */ |
| 97 | | static object_pool *pools[64]; |
| 98 | | |
| 99 | | /* resource tracking */ |
| 100 | | int resource_tracking_tag = 0; |
| 101 | | |
| 102 | | |
| 103 | | |
| 104 | | /*************************************************************************** |
| 105 | | PROTOTYPES |
| 106 | | ***************************************************************************/ |
| 107 | | |
| 108 | | /*************************************************************************** |
| 109 | | CORE IMPLEMENTATION |
| 110 | | ***************************************************************************/ |
| 111 | | /*------------------------------------------------- |
| 112 | | current_pool - identifies the current memory |
| 113 | | pool |
| 114 | | -------------------------------------------------*/ |
| 115 | | |
| 116 | | static object_pool *current_pool(void) |
| 117 | | { |
| 118 | | object_pool *pool; |
| 119 | | assert_always((resource_tracking_tag > 0) && (resource_tracking_tag <= ARRAY_LENGTH(pools)), "Invalid resource_tracking_tag"); |
| 120 | | pool = pools[resource_tracking_tag - 1]; |
| 121 | | assert_always(pool != NULL, "current_pool() is NULL"); |
| 122 | | return pool; |
| 123 | | } |
| 124 | | |
| 125 | | |
| 126 | | /*------------------------------------------------- |
| 127 | | restrack_register_object - registers an |
| 128 | | object with the current pool |
| 129 | | -------------------------------------------------*/ |
| 130 | | |
| 131 | | void *restrack_register_object(object_type type, void *ptr, size_t size, const char *file, int line) |
| 132 | | { |
| 133 | | return pool_object_add_file_line(current_pool(), type, ptr, size, file, line); |
| 134 | | } |
| 135 | | |
| 136 | | |
| 137 | | /*------------------------------------------------- |
| 138 | | auto_malloc_file_line - allocate auto- |
| 139 | | freeing memory |
| 140 | | -------------------------------------------------*/ |
| 141 | | |
| 142 | | void *auto_malloc_file_line(running_machine &machine, size_t size, const char *file, int line) |
| 143 | | { |
| 144 | | void *result = pool_malloc_file_line(current_pool(), size, file, line); |
| 145 | | return result; |
| 146 | | } |
| 147 | | |
| 148 | | |
| 149 | | /*------------------------------------------------- |
| 150 | | auto_realloc_file_line - reallocate auto- |
| 151 | | freeing memory |
| 152 | | -------------------------------------------------*/ |
| 153 | | |
| 154 | | void *auto_realloc_file_line(running_machine &machine, void *ptr, size_t size, const char *file, int line) |
| 155 | | { |
| 156 | | object_pool *pool = current_pool(); |
| 157 | | if (ptr != NULL) |
| 158 | | { |
| 159 | | int tag = resource_tracking_tag; |
| 160 | | for (; tag > 0; tag--) |
| 161 | | { |
| 162 | | pool = pools[tag - 1]; |
| 163 | | if (pool_object_exists(pool, OBJTYPE_MEMORY, ptr)) |
| 164 | | break; |
| 165 | | } |
| 166 | | assert_always(tag > 0, "Failed to find alloc in pool"); |
| 167 | | } |
| 168 | | |
| 169 | | return pool_realloc_file_line(pool, ptr, size, file, line); |
| 170 | | } |
| 171 | | |
| 172 | | |
| 173 | | /*------------------------------------------------- |
| 174 | | auto_strdup_file_line - allocate auto-freeing |
| 175 | | string |
| 176 | | -------------------------------------------------*/ |
| 177 | | |
| 178 | | char *auto_strdup_file_line(running_machine &machine, const char *str, const char *file, int line) |
| 179 | | { |
| 180 | | return pool_strdup_file_line(current_pool(), str, file, line); |
| 181 | | } |
| 182 | | |
| 183 | | |
| 184 | | /*------------------------------------------------- |
| 185 | | auto_strdup_allow_null_file_line - allocate |
| 186 | | auto-freeing string if str is null |
| 187 | | -------------------------------------------------*/ |
| 188 | | |
| 189 | | char *auto_strdup_allow_null_file_line(running_machine &machine, const char *str, const char *file, int line) |
| 190 | | { |
| 191 | | return (str != NULL) ? auto_strdup_file_line(machine, str, file, line) : NULL; |
| 192 | | } |
| 193 | | |
| 194 | | |
| 195 | | |
| 196 | | void *malloc_or_die_file_line(size_t size, const char *file, int line) |
| 197 | | { |
| 198 | | return malloc(size); |
| 199 | | } |