zbrk_struct *zr_get_free(z_records *zrecs, zb_code *addr) { z_records temp; zbrk_struct *z_ptr; /* NOTE: records are stored by decreasing addresses */ assert(zrecs->free < zrecs->end); for (z_ptr = zrecs->beg; z_ptr < zrecs->free; z_ptr++) { if (z_ptr->mpc == addr) return (z_ptr); if (z_ptr->mpc < addr) /* insert here */ break; } assert(z_ptr == zrecs->free || z_ptr->mpc < addr); if (1 == zrecs->end - zrecs->free) /* expand if necessary */ { temp = *zrecs; zr_init(zrecs, 2 * (int)(zrecs->end - zrecs->beg)); assert(2 * (temp.end - temp.beg) == (zrecs->end - zrecs->beg)); memcpy((char *)zrecs->beg, (char *)temp.beg, (temp.free - temp.beg) * sizeof(zbrk_struct)); assert(zrecs->free == zrecs->beg); zrecs->free += (temp.free - temp.beg); z_ptr = zrecs->beg + (z_ptr - temp.beg); free(temp.beg); } /* shift records down into the bottom spot which was allocated */ memmove((char *)(z_ptr + 1), (char *)z_ptr, (zrecs->free - z_ptr) * sizeof(zbrk_struct)); memset((char *)z_ptr, 0, sizeof(zbrk_struct)); z_ptr->mpc = addr; zrecs->free++; return (z_ptr); }
static void zrmenu_init_device(zrmenu_handle_t *zr) { char buf[PATH_MAX_LENGTH]; fill_pathname_join(buf, zr->assets_directory, "DroidSans.ttf", sizeof(buf)); zr_alloc.userdata.ptr = NULL; zr_alloc.alloc = zr_common_mem_alloc; zr_alloc.free = zr_common_mem_free; zr_buffer_init(&device.cmds, &zr_alloc, 1024); usrfnt = zr_common_font(&device, &font, buf, 16, zr_font_default_glyph_ranges()); zr_init(&zr->ctx, &zr_alloc, &usrfnt); zr_common_device_init(&device); fill_pathname_join(buf, zr->assets_directory, "folder.png", sizeof(buf)); zr->icons.folder = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "speaker.png", sizeof(buf)); zr->icons.speaker = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "gamepad.png", sizeof(buf)); zr->icons.gamepad = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "monitor.png", sizeof(buf)); zr->icons.monitor = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "settings.png", sizeof(buf)); zr->icons.settings = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "invader.png", sizeof(buf)); zr->icons.invader = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "page_on.png", sizeof(buf)); zr->icons.page_on = zr_common_image_load(buf); fill_pathname_join(buf, zr->assets_directory, "page_off.png", sizeof(buf)); zr->icons.page_off = zr_common_image_load(buf); zrmenu_set_style(&zr->ctx, THEME_DARK); zr->size_changed = true; }