static int image_load_internal(mess_image *image, const char *path, int is_create, int create_format, option_resolution *create_args) { image_error_t err; const char *software_path; char *software_path_list = NULL; const void *buffer; const game_driver *gamedrv; UINT32 open_plan[4]; int i; /* sanity checks */ assert_always(image, "image_load(): image is NULL"); assert_always(path, "image_load(): path is NULL"); /* we are now loading */ image->is_loading = 1; /* first unload the image */ image_unload(image); /* record the filename */ image->err = set_image_filename(image, path, NULL); if (image->err) goto done; /* tell the OSD layer that this is changing */ osd_image_load_status_changed(image, 0); /* do we need to reset the CPU? */ if ((timer_get_time() > 0) && image->dev->reset_on_load) mame_schedule_soft_reset(Machine); /* determine open plan */ determine_open_plan(image, is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !image->file && open_plan[i]; i++) { software_path = software_path_list; do { gamedrv = Machine->gamedrv; while(!is_loaded(image) && gamedrv) { /* open the file */ image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path); if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND)) goto done; /* move on to the next driver */ gamedrv = mess_next_compatible_driver(gamedrv); } /* move on to the next entry in the software path; if we can */ if (software_path) software_path += strlen(software_path) + 1; } while(!is_loaded(image) && software_path && *software_path); } /* did we fail to find the file? */ if (!is_loaded(image)) { image->err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* if applicable, call device verify */ if (image->dev->imgverify && !image_has_been_created(image)) { /* access the memory */ buffer = image_ptr(image); if (!buffer) { image->err = IMAGE_ERROR_OUTOFMEMORY; goto done; } /* verify the file */ err = image->dev->imgverify(buffer, (size_t) image->length); if (err) { image->err = IMAGE_ERROR_INVALIDIMAGE; goto done; } } /* call device load or create */ if (image_has_been_created(image) && image->dev->create) { err = image->dev->create(image, create_format, create_args); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } else if (image->dev->load) { /* using device load */ err = image->dev->load(image); if (err) { if (!image->err) image->err = IMAGE_ERROR_UNSPECIFIED; goto done; } } /* success! */ done: if (software_path_list) free(software_path_list); if (image->err) image_clear(image); image->is_loading = 1; return image->err ? INIT_FAIL : INIT_PASS; }
char *image_strdup(mess_image *image, const char *src) { assert(is_loaded(image) || image->is_loading); return pool_strdup(&image->mempool, src); }
static image_error_t load_image_by_path(mess_image *image, const char *software_path, const game_driver *gamedrv, UINT32 open_flags, const char *path) { mame_file_error filerr = FILERR_NOT_FOUND; image_error_t err = IMAGE_ERROR_FILENOTFOUND; char *full_path = NULL; const char *file_extension; /* assemble the path */ if (software_path) { full_path = assemble_5_strings(software_path, PATH_SEPARATOR, gamedrv->name, PATH_SEPARATOR, path); path = full_path; } /* quick check to see if the file is a ZIP file */ file_extension = strrchr(path, '.'); if (!file_extension || mame_stricmp(file_extension, ".zip")) { filerr = osd_open(path, open_flags, &image->file, &image->length); /* did the open succeed? */ switch(filerr) { case FILERR_NONE: /* success! */ image->writeable = (open_flags & OPEN_FLAG_WRITE) ? 1 : 0; image->created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0; err = IMAGE_ERROR_SUCCESS; break; case FILERR_NOT_FOUND: case FILERR_ACCESS_DENIED: /* file not found (or otherwise cannot open); continue */ err = IMAGE_ERROR_FILENOTFOUND; break; case FILERR_OUT_OF_MEMORY: /* out of memory */ err = IMAGE_ERROR_OUTOFMEMORY; break; case FILERR_ALREADY_OPEN: /* this shouldn't happen */ err = IMAGE_ERROR_ALREADYOPEN; break; case FILERR_FAILURE: case FILERR_TOO_MANY_FILES: case FILERR_INVALID_DATA: default: /* other errors */ err = IMAGE_ERROR_INTERNAL; break; } } /* special case for ZIP files */ if ((err == IMAGE_ERROR_FILENOTFOUND) && (open_flags == OPEN_FLAG_READ)) err = load_zip_path(image, path); /* check to make sure that our reported error is reflective of the actual status */ if (err) assert(!is_loaded(image)); else assert(is_loaded(image)); /* free up memory, and exit */ if (full_path) free(full_path); return err; }
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load) { UINT32 open_plan[4]; int i; bool softload = FALSE; m_from_swlist = FALSE; // if the path contains no period, we are using softlists, so we won't create an image astring pathstr(path); bool filename_has_period = (pathstr.rchr(0, '.') != -1) ? TRUE : FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ m_err = set_image_filename(path); if (m_err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ if (!filename_has_period && !just_load) { softload = load_software_part( device().machine().options(), this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name, &m_software_list_name ); // if we had launched from softlist with a specified part, e.g. "shortname:part" // we would have recorded the wrong name, so record it again based on software_info if (m_software_info_ptr && m_full_software_name) m_err = set_image_filename(m_full_software_name); m_from_swlist = TRUE; } if (is_create || filename_has_period) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } /* success! */ done: if (just_load) { if(m_err) clear(); return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if (device().machine().time() > attotime::zero && is_reset_on_load()) device().machine().schedule_hard_reset(); else { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
void *image_realloc(mess_image *image, void *ptr, size_t size) { assert(is_loaded(image) || image->is_loading); return pool_realloc(&image->mempool, ptr, size); }
// Renames a the file with the specified index to the new name. The new // filename is reflected by the ``file_storage`` returned by ``files()`` // but not by the one returned by ``orig_files()``. // // If you want to rename the base name of the torrent (for a multifile // torrent), you can copy the ``file_storage`` (see files() and // orig_files() ), change the name, and then use `remap_files()`_. // // The ``new_filename`` can both be a relative path, in which case the // file name is relative to the ``save_path`` of the torrent. If the // ``new_filename`` is an absolute path (i.e. ``is_complete(new_filename) // == true``), then the file is detached from the ``save_path`` of the // torrent. In this case the file is not moved when move_storage() is // invoked. void rename_file(int index, std::string const& new_filename) { TORRENT_ASSERT(is_loaded()); copy_on_write(); m_files.rename_file(index, new_filename); }
inline std::vector<sgraph_vertex_data>& get_partition(size_t partition_id) { DASSERT_LT(partition_id, m_num_partitions); DASSERT_TRUE(is_loaded(partition_id)); return m_vertex_partitions[partition_id]; }
int load_plugin(const char *plugin_name) { void *handle; char *error; char path[PATHSIZE]; int (*init_plugin) (void); char **deps; char **plugin_info; plugin_t *p; if (is_loaded(plugin_name)) { printf("Plugin %s already loaded.\n", plugin_name); return 0; } strncpy(path, PLUGINDIR, PATHSIZE); strncat(path, "/plugin_", PATHSIZE); strncat(path, plugin_name, PATHSIZE); strncat(path, ".so", PATHSIZE); #if DEBUG printf("Opening plugin %s\n", path); #endif handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); if (!handle) { error = dlerror(); printf("Error: Could not open plugin \"%s\": %s\n", plugin_name, error); exit(1); } #ifdef DEBUG_PLUGINS plugin_info = dlsym(handle, "plugin_author"); if ((error = dlerror()) == NULL) printf("Plugin %s author: %s\n", plugin_name, *plugin_info); plugin_info = dlsym(handle, "plugin_license"); if ((error = dlerror()) == NULL) printf("Plugin %s license: %s\n", plugin_name, *plugin_info); plugin_info = dlsym(handle, "plugin_description"); if ((error = dlerror()) == NULL) printf("Plugin %s descr.: %s\n", plugin_name, *plugin_info); #endif p = malloc(sizeof(plugin_t)); p->next = plugins; p->name = plugin_name; plugins = p; deps = dlsym(handle, "plugin_deps"); if ((error = dlerror()) != NULL) deps = NULL; strncpy(path, "plugin_", PATHSIZE); strncat(path, plugin_name, PATHSIZE); strncat(path, "_init", PATHSIZE); init_plugin = dlsym(handle, path); if ((error = dlerror()) != NULL) { printf("error: %s\n", error); exit(1); } if (deps) { int i = 0; char *walk = deps[0]; #ifdef DEBUG_PLUGINS printf("\nPlugin %s dependencies:", plugin_name); #endif while (walk) { printf(" %s", walk); if (!is_loaded(walk)) { #ifdef DEBUG_PLUGINS printf("(loading)\n"); #endif load_plugin(walk); } #ifdef DEBUG_PLUGINS else { printf("(loaded)"); } #endif walk = deps[++i]; } } printf("\n"); #if DEBUG printf("Initializing module:\n"); #endif return init_plugin(); // We don't dlclose the handle here since // we want to keep our symbols for later use. }
std::vector <osg::Vec2> LeafGrower::texture_coords_from_vertex(const std::vector <osg::Vec3>& all_v) { std::vector <osg::Vec2> ret; if(!is_loaded()) return ret; std::vector <osg::Vec3> ABEF(4, osg::Vec3(0, 0, 0));//planar leaves //for each vertex, find its texture coordinates for(unsigned int i=0; i<all_v.size(); i++) { osg::Vec3 v = all_v[i]; //find which quadrant does it lay osg::Vec3 normal = v - _cg; int region = which_quadrant(normal); //for rotation osg::Matrixf R; //front if(region == 0) R.makeIdentity(); //right, rotate to front by -120 if(region == 1) R.makeRotate(osg::Vec3(0, 1, 0), osg::Vec3(0.866025403, -0.5, 0)); //left, rotate to front by +120 if(region == 2) R.makeRotate(osg::Vec3(0, 1, 0), osg::Vec3(-0.866025403, -0.5, 0)); //top, rotate to front by -60 if(region == 3) //R.makeRotate(osg::Vec3(0, 0, 1), osg::Vec3(0, -1, 0)); R.makeRotate(osg::Vec3(0, 0, 1), osg::Vec3(0, -0.866025403, 0.5)); //bottom, rotate to front by +60 if(region == 4) //R.makeRotate(osg::Vec3(0, 0, -1), osg::Vec3(0, -1, 0)); R.makeRotate(osg::Vec3(0, 0, -1), osg::Vec3(0, -0.866025403, -0.5)); if(i%4 != 3) { ABEF[i%4] = v; continue; } else { ABEF[3] = v; //to prevent different corner points multiple to different rotations //so use the last R to apply to all for(int j=0; j<4; j++) { ABEF[j] = (ABEF[j]-_cg) * R + _cg; osg::Vec2 img_space = obj_to_img_space(ABEF[j]); //further transform it to real texture space by bound osg::Vec2 tex_space = img_space - _bound_bottomLeft;//for texture mapping, origin is at bottomLeft tex_space.y() *= -1.0f; //normalized it to within 0 <= x <= 1 osg::Vec2 tex_coord(tex_space.x()/float(_bound_width), tex_space.y()/float(_bound_height)); ret.push_back(tex_coord); } } } return ret; }
bool psxcard_device::transfer(UINT8 to, UINT8 *from) { bool ret=true; switch (state) { case state_illegal: if (is_loaded()) { // printf("CARD: begin\n"); state = state_command; *from = 0x00; } else { ret = false; } break; case state_command: cmd=to; *from=0x5a; state=state_cmdack; break; case state_cmdack: *from=0x5d; state=state_wait; break; case state_wait: *from=0x00; state=state_addr_hi; break; case state_addr_hi: addr=(to<<8); // printf("addr_hi: %02x, addr = %x\n", to, addr); *from=to; state=state_addr_lo; break; case state_addr_lo: addr|=(to&0xff); // printf("addr_lo: %02x, addr = %x, cmd = %x\n", to, addr, cmd); switch (cmd) { case 'R': // 0x52 { pkt[0]=*from=0x5c; pkt[1]=0x5d; pkt[2]=(addr>>8); pkt[3]=(addr&0xff); read_card(addr,&pkt[4]); pkt[4+128]=checksum_data(&pkt[2],128+2); pkt[5+128]=0x47; pkt_sz=6+128; pkt_ptr=1; state=state_read; break; } case 'W': // 0x57 { pkt[0]=addr>>8; pkt[1]=addr&0xff; pkt_sz=129+2; pkt_ptr=2; state=state_write; *from=to; break; } default: state=state_illegal; break; } break; case state_read: //assert(to==0); // printf("state_read: pkt_ptr = %d, pkt_sz = %d\n", pkt_ptr, pkt_sz); *from=pkt[pkt_ptr++]; if (pkt_ptr==pkt_sz) { #ifdef debug_card printf("card: read finished\n"); #endif state=state_end; } break; case state_write: *from=to; pkt[pkt_ptr++]=to; if (pkt_ptr==pkt_sz) { *from=0x5c; state=state_writeack_2; } break; case state_writeack_2: *from=0x5d; state=state_writechk; break; case state_writechk: { unsigned char chk=checksum_data(pkt,128+2); if (chk==pkt[128+2]) { #ifdef debug_card printf("card: write ok\n"); #endif write_card(addr,pkt+2); *from='G'; } else { #ifdef debug_card printf("card: write fail\n"); #endif *from='N'; } state=state_end; break; } case state_end: ret = false; state = state_illegal; break; default: /*assert(0);*/ ret=false; break; } #ifdef debug_card // printf("card: transfer to=%02x from=%02x ret=%c\n",to,*from,ret ? 'T' : 'F'); #endif return ret; }
void inc_refcount() { TORRENT_ASSERT(is_loaded()); ++m_refcount; }
bool legacy_image_device_base::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args) { UINT32 open_plan[4]; int i; bool softload = FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ m_err = set_image_filename(path); if (m_err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ softload = load_software_part( this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name ); if (is_create || (!softload && m_software_info_ptr==NULL)) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } /* success! */ done: if (m_err!=0) { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if ((attotime_compare(timer_get_time(device().machine), attotime_zero) > 0) && m_image_config.is_reset_on_load()) device().machine->schedule_hard_reset(); else { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
// This function will map a range in a specific file into a range in the // torrent. The ``file_offset`` parameter is the offset in the file, // given in bytes, where 0 is the start of the file. See peer_request. // // The input range is assumed to be valid within the torrent. // ``file_offset`` + ``size`` is not allowed to be greater than the file // size. ``file_index`` must refer to a valid file, i.e. it cannot be >= // ``num_files()``. peer_request map_file(int file, boost::int64_t offset, int size) const { TORRENT_ASSERT(is_loaded()); return m_files.map_file(file, offset, size); }
// This function will map a piece index, a byte offset within that piece // and a size (in bytes) into the corresponding files with offsets where // that data for that piece is supposed to be stored. See file_slice. std::vector<file_slice> map_block(int piece, boost::int64_t offset, int size) const { TORRENT_ASSERT(is_loaded()); return m_files.map_block(piece, offset, size); }
/** * @brief Destructor. */ Tileset::~Tileset() { if (is_loaded()) { unload(); // destroy the tiles } }
// ------------------------------------------------------------------ // ciKlass::find_klass // // Find a klass using this klass's class loader. ciKlass* ciKlass::find_klass(ciSymbol* klass_name) { assert(is_loaded(), "cannot find_klass through an unloaded klass"); return CURRENT_ENV->get_klass_by_name(this, klass_name, false); }
void check_is_loaded() const { assert(is_loaded(), "not loaded"); }
file_storage const& orig_files() const { TORRENT_ASSERT(is_loaded()); return m_orig_files ? *m_orig_files : m_files; }