int image_init(void) { int err; int count, indx, i, j; UINT32 mask, dev_mask = 0; /* setup the globals */ images = NULL; multiple_dev_mask = 0; /* first count all images, and identify multiply defined devices */ count = 0; for (i = 0; Machine->devices[i].type < IO_COUNT; i++) { /* check to see if this device type is used multiple times */ mask = 1 << Machine->devices[i].type; if (dev_mask & mask) multiple_dev_mask |= mask; else dev_mask |= mask; /* increment the count */ count += Machine->devices[i].count; } /* allocate the array */ if (count > 0) { images = auto_malloc(count * sizeof(*images)); memset(images, 0, count * sizeof(*images)); } /* initialize the devices */ indx = 0; for (i = 0; Machine->devices[i].type < IO_COUNT; i++) { for (j = 0; j < Machine->devices[i].count; j++) { /* setup the device */ tagpool_init(&images[indx + j].tagpool); images[indx + j].dev = &Machine->devices[i]; if (Machine->devices[i].init) { err = Machine->devices[i].init(&images[indx + j]); if (err != INIT_PASS) return err; } } indx += Machine->devices[i].count; } add_exit_callback(Machine, image_exit); return INIT_PASS; }
/* basic floppy_image initialization common to floppy_open() and floppy_create() */ static floppy_image *floppy_init(void *fp, const struct io_procs *procs, int flags) { floppy_image *floppy; floppy = malloc(sizeof(struct _floppy_image)); if (!floppy) return NULL; memset(floppy, 0, sizeof(*floppy)); tagpool_init(&floppy->tags); floppy->io.file = fp; floppy->io.procs = procs; floppy->io.filler = 0xFF; floppy->flags = (UINT8) flags; return floppy; }