src/emu/diimage.c
| r11655 | r11656 | |
| 39 | 39 | |
| 40 | 40 | #include "emu.h" |
| 41 | 41 | #include "ui.h" |
| 42 | | #include "pool.h" |
| 43 | 42 | #include "zippath.h" |
| 44 | 43 | |
| 45 | 44 | |
| r11655 | r11656 | |
| 70 | 69 | // DEVICE IMAGE INTERFACE |
| 71 | 70 | //************************************************************************** |
| 72 | 71 | |
| 73 | | /*------------------------------------------------- |
| 74 | | memory_error - report a memory error |
| 75 | | -------------------------------------------------*/ |
| 76 | | |
| 77 | | static void memory_error(const char *message) |
| 78 | | { |
| 79 | | fatalerror("%s", message); |
| 80 | | } |
| 81 | | |
| 82 | | |
| 83 | 72 | //------------------------------------------------- |
| 84 | 73 | // device_image_interface - constructor |
| 85 | 74 | //------------------------------------------------- |
| r11655 | r11656 | |
| 94 | 83 | m_readonly(false), |
| 95 | 84 | m_created(false) |
| 96 | 85 | { |
| 97 | | m_mempool = pool_alloc_lib(memory_error); |
| 98 | 86 | } |
| 99 | 87 | |
| 100 | 88 | |
| r11655 | r11656 | |
| 104 | 92 | |
| 105 | 93 | device_image_interface::~device_image_interface() |
| 106 | 94 | { |
| 107 | | pool_free_lib(m_mempool); |
| 108 | 95 | } |
| 109 | 96 | |
| 110 | 97 | //------------------------------------------------- |
| r11655 | r11656 | |
| 450 | 437 | } |
| 451 | 438 | |
| 452 | 439 | /**************************************************************************** |
| 453 | | Memory allocators |
| 454 | | |
| 455 | | These allow memory to be allocated for the lifetime of a mounted image. |
| 456 | | If these (and the above accessors) are used well enough, they should be |
| 457 | | able to eliminate the need for a unload function. |
| 458 | | ****************************************************************************/ |
| 459 | | |
| 460 | | void *device_image_interface::image_malloc(size_t size) |
| 461 | | { |
| 462 | | return image_realloc(NULL, size); |
| 463 | | } |
| 464 | | |
| 465 | | char *device_image_interface::image_strdup(const char *src) |
| 466 | | { |
| 467 | | return pool_strdup_lib(m_mempool, src); |
| 468 | | } |
| 469 | | |
| 470 | | void *device_image_interface::image_realloc(void *ptr, size_t size) |
| 471 | | { |
| 472 | | return pool_realloc_lib(m_mempool, ptr, size); |
| 473 | | } |
| 474 | | |
| 475 | | void device_image_interface::image_freeptr(void *ptr) |
| 476 | | { |
| 477 | | pool_object_remove(m_mempool, ptr, 0); |
| 478 | | } |
| 479 | | |
| 480 | | |
| 481 | | /**************************************************************************** |
| 482 | 440 | Hash info loading |
| 483 | 441 | |
| 484 | 442 | If the hash is not checked and the relevant info not loaded, force that info |
src/emu/diimage.h
| r11655 | r11656 | |
| 46 | 46 | #ifndef __DIIMAGE_H__ |
| 47 | 47 | #define __DIIMAGE_H__ |
| 48 | 48 | |
| 49 | | #include "pool.h" |
| 50 | | |
| 51 | 49 | //************************************************************************** |
| 52 | 50 | // TYPE DEFINITIONS |
| 53 | 51 | //************************************************************************** |
| r11655 | r11656 | |
| 245 | 243 | UINT32 get_software_region_length(const char *tag); |
| 246 | 244 | const char *get_feature(const char *feature_name); |
| 247 | 245 | |
| 248 | | void *image_malloc(size_t size); |
| 249 | | char *image_strdup(const char *src); |
| 250 | | void *image_realloc(void *ptr, size_t size); |
| 251 | | void image_freeptr(void *ptr); |
| 252 | | |
| 253 | 246 | UINT32 crc(); |
| 254 | 247 | hash_collection& hash() { return m_hash; } |
| 255 | 248 | |
| r11655 | r11656 | |
| 310 | 303 | int m_create_format; |
| 311 | 304 | option_resolution *m_create_args; |
| 312 | 305 | |
| 313 | | object_pool *m_mempool; |
| 314 | | |
| 315 | 306 | hash_collection m_hash; |
| 316 | 307 | }; |
| 317 | 308 | |
src/mess/devices/sonydriv.c
| r11655 | r11656 | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | track_size = floppy_get_track_size(fimg, f->head, floppy_drive_get_current_track(&cur_image->device())); |
| 122 | | new_data = (UINT8*)cur_image->image_realloc(f->loadedtrack_data, track_size); |
| 122 | if (f->loadedtrack_data) auto_free(device->machine(),f->loadedtrack_data); |
| 123 | new_data = auto_alloc_array(device->machine(),UINT8,track_size); |
| 123 | 124 | if (!new_data) |
| 124 | 125 | { |
| 125 | 126 | return; |
| r11655 | r11656 | |
| 520 | 521 | |
| 521 | 522 | sony.floppy[0].is_fdhd = 0; |
| 522 | 523 | sony.floppy[1].is_fdhd = 0; |
| 524 | sony.floppy[0].loadedtrack_data = NULL; |
| 525 | sony.floppy[1].loadedtrack_data = NULL; |
| 523 | 526 | } |
| 524 | 527 | |
| 525 | 528 | static DEVICE_IMAGE_UNLOAD( sonydriv_floppy ) |
src/mess/machine/nes.c
| r11655 | r11656 | |
| 1650 | 1650 | state->m_fds_sides = (image.length() - header) / 65500; |
| 1651 | 1651 | |
| 1652 | 1652 | if (state->m_fds_data == NULL) |
| 1653 | | state->m_fds_data = (UINT8*)image.image_malloc(state->m_fds_sides * 65500); // I don't think we can arrive here ever, probably it can be removed... |
| 1653 | state->m_fds_data = auto_alloc_array(image.device().machine(),UINT8,state->m_fds_sides * 65500); // I don't think we can arrive here ever, probably it can be removed... |
| 1654 | 1654 | |
| 1655 | 1655 | /* if there is an header, skip it */ |
| 1656 | 1656 | image.fseek(header, SEEK_SET); |
src/mess/machine/msx.c
| r11655 | r11656 | |
| 124 | 124 | while (size_aligned < size) { |
| 125 | 125 | size_aligned *= 2; |
| 126 | 126 | } |
| 127 | | mem = (UINT8*)image.image_malloc(size_aligned); |
| 127 | mem = auto_alloc_array(image.device().machine(),UINT8,size_aligned); |
| 128 | 128 | if (!mem) { |
| 129 | 129 | logerror ("cart #%d: error: failed to allocate memory for cartridge\n", |
| 130 | 130 | id); |
| r11655 | r11656 | |
| 177 | 177 | if (!type && size_aligned != 0x10000) |
| 178 | 178 | { |
| 179 | 179 | size_aligned = 0x10000; |
| 180 | | mem = (UINT8*)image.image_realloc(mem, 0x10000); |
| 180 | auto_free(image.device().machine(),mem); |
| 181 | mem = auto_alloc_array(image.device().machine(),UINT8, 0x10000); |
| 181 | 182 | if (!mem) { |
| 182 | 183 | logerror ("cart #%d: error: cannot allocate memory\n", id); |
| 183 | 184 | return IMAGE_INIT_FAIL; |
| r11655 | r11656 | |
| 251 | 252 | } |
| 252 | 253 | |
| 253 | 254 | /* allocate and set slot_state for this cartridge */ |
| 254 | | st = (slot_state*) image.image_malloc(sizeof (slot_state)); |
| 255 | st = auto_alloc(image.device().machine(),slot_state); |
| 255 | 256 | if (!st) |
| 256 | 257 | { |
| 257 | 258 | logerror ("cart #%d: error: cannot allocate memory for " |
| r11655 | r11656 | |
| 261 | 262 | memset (st, 0, sizeof (slot_state)); |
| 262 | 263 | |
| 263 | 264 | st->m_type = type; |
| 264 | | sramfile = (char*)image.image_malloc(strlen (image.filename () + 1)); |
| 265 | sramfile = auto_alloc_array(image.device().machine(), char, strlen (image.filename () + 1)); |
| 265 | 266 | |
| 266 | 267 | if (sramfile) { |
| 267 | 268 | char *ext; |